I would like to write a script in Python using pywinrm library to be able to connect to remote machine via WinRM.
import winrm
s = winrm.Session(\'MACHINEH
Open command prompt and type:
winrm qc
winrm set winrm/config/service @{AllowUnencrypted="true"}
Open Powershell and type:
enable-psremoting
set-item WSMan:\localhost\Client\TrustedHosts * # ('*' is for all hosts, you may specify the host you want)
In your python script:
import winrm
host = 'YourWindowsHost'
domain = 'YourDomain'
user = 'YourDomainUser'
password = 'YourPassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')
result = session.run_cmd('ipconfig', ['/all']) # To run command in cmd
result = session.run_ps('Get-Acl') # To run Powershell block