-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect_winrm.py
38 lines (33 loc) · 1.42 KB
/
connect_winrm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from lib.WinRM_Python import WinRmPython
if __name__ == "__main__":
# Replace with your server details and credentials
server = "hostname" # Replace with the server's IP or hostname
username = "devuser" # Replace with the username
password = "Password" # Replace with the password
script_path = "D:/abc/script.ps1" # Replace with the path to your PowerShell script file
auth_method = "ntlm" # Options: 'ntlm', 'kerberos', 'basic'
use_ssl = False # Set to True if SSL is required
try:
# Initialize the class with authentication and SSL options
executor = WinRmPython(server, username, password, auth=auth_method, ssl=use_ssl)
# Establish connection
executor.establish_connection()
params = {
"FirstName": "Test",
"LastName": "User",
}
# Read the PowerShell script
script_content = executor.read_script(script_path, **params)
# Execute the PowerShell script
result = executor.execute_script(script_content)
# Output the result
if result["status"] == "success":
print("Script executed successfully!")
print("Output:")
print(result["output"])
else:
print("Error executing script!")
print("Error message:")
print(result["error_message"])
except Exception as e:
print(f"An error occurred: {e}")