我在成功运行作为python脚本一部分的powershell脚本时遇到了一些困难。问题不是脚本不运行,即使我尝试导入,也无法识别来自已安装的powershell模块的命令。具体的命令是Connect MSOLService和同一模块中的其他命令。在
我写了一个小测试来尝试我们不同的东西,但似乎没有任何效果。在测试中,我尝试了以下方法:
subprocess.call('powershell ./script.ps1"')
或者
p = subprocess.Popen(['powershell.exe', '-NoProfile', '-Command', '"&{' + pscommand + '}"'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate()
或者
subprocess.call('powershell.exe ./script.ps1"')
除MSOL命令外,所有这些都成功运行脚本,始终返回this错误:
Connect-MsolService : The term 'Connect-MsolService' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At C:\Users\user\desktop\scripts\script.ps1:20 char:9
+ Connect-MsolService -Credential $LiveCred
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Connect-MsolService:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
当从python脚本外部运行时,执行策略设置为unrestricted,问题只在我使用时发生subprocess.call()在Python中。如有任何建议/帮助,我们将不胜感激。在
谢谢, 卢
在尝试了这个并得到了同样的错误。我发现Python正在调用32位版本的PowerShell,但未能导入64位模块。上面的代码能够从32位Python调用64位版本的PowerShell,然后运行包含 [连接MsolService]。在
相关问题 更多 >
编程相关推荐