我想远程执行powershell命令并获取输出。
命令是“(New Object-cMicrosoft.Update.Session).createUpdateSearch().Search(“IsInstalled=0”).Updates |选择标题“。
我试过了
import wmi
try:
connection = wmi.WMI(ip, user=username, password=password)
print("connection is established")
connection.Win32_Process.Create(CommandLine='powershell.exe /c (New-Object -c Microsoft.Update.Session).CreateUpdateSearcher().Search("IsInstalled=0").Updates|Select Title > C:\output.txt')
except:
print("connection failed")
你需要注意转义字符。试试这个:
相关问题 更多 >
编程相关推荐