【发布时间】:2017-05-26 06:20:55
【问题描述】:
这里我们可以看到一些例子: https://github.com/diyan/pywinrm 如何通过pywinrm和powershell脚本控制windows 这是工作。
万一
ps_script = """$strComputer = $Host
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Python27\Scripts", [EnvironmentVariableTarget]::Machine)
Restart-Computer
"""
它将 python 添加到 PATH,但不重新启动 Windows。
万一
ps_script = """Write-Host "hello"
"""
我在我的机器终端上看到“你好”,而不是远程。
怎么了?
【问题讨论】:
-
几个想法。您尝试重新启动哪个版本的 Windows?使用什么版本的 PowerShell?如果我没记错的话,直到 PowerShell 3.0 才添加 Restart-Computer。其次,如果添加
-force参数会发生什么? -
@BenH, "restart-computer -force" 成功。但是什么权利? Windows server 2012, powershell 3.0 我的用户已经在管理组中。
-
实际上,
Retart-Computer -ForceAFAIR 只是忽略了远程机器上有活动的会话这一事实。没有它,如果存在任何会话,PowerShell 将返回错误。检查您从response获得的std_err对象(只是猜测,因为您跳过了代码的那部分)run_ps方法。
标签: powershell python-2.x winrm