Custom Search

Thursday, October 24, 2013

How to execute powershell command remotely from linux using Python

1)
Install freeSSHd on your Windows System
http://fosshelp.blogspot.in/2013/10/how-to-ssh-to-windows-from-linux-using.html

2)
Execute following Python script From Your Linux System
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print "\nConnecting"
ssh.connect('192.168.1.7', username='saju', password='saju')
print "\nConnected"
##Supported -OutputFormat Text, XML, none
cmd = "powershell -InputFormat none -OutputFormat TEXT Get-VMHost"
stdin, stdout, stderr = ssh.exec_command(cmd)
print stdout.readlines()



3)
Text Output


4)
XML OUTPUT


5)
Output from Powershell



No comments:

Post a Comment