How can I execute command on remote Windows using Python? Best methods and examples?

14 Replies, 2142 Views

If you’re looking to execute command on remote windows using python, I’d recommend checking out `pypsrp`. It’s another library that works over WinRM and is pretty straightforward to use.

One advantage of pypsrp is that it supports both PowerShell and cmd commands, so you’ve got flexibility.

Here’s a quick example:
```python
from pypsrp.powershell import RunspacePool
with RunspacePool('remote-pc', username='user', password='pass') as pool:
ps = pool.run_script('Get-Process')
print(ps.output)
```

Also, if you’re dealing with firewalls, make sure port 5985 (HTTP) or 5986 (HTTPS) is open.

Good luck with your project!

Messages In This Thread



Users browsing this thread: 1 Guest(s)