rundeck无法使用importmodu执行powershell脚本

2024-05-15 02:31:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在windows2012目标节点上通过rundeck(在线)运行几个python脚本。这些脚本以前在本地运行,但现在正在迁移到rundeck。在

其中一个python脚本打开子进程来调用powershell脚本并读取输出。在

import subprocess
CMD = [r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe ', '-File', r'C:\Users\Osman\Code\mop.ps1']
cmd = CMD[:]
cmd.append('arg1')
cmd.append('arg2')
cmd.append('arg3')
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
r = p.communicate()
print(r)

在澳门币ps1是

^{pr2}$

这部分代码总是无法执行,如果我检查stderr,它会显示:

        Connect-MsolService : Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown.
At C:\Users\Osman\Code\mop.ps1:7 char:1 
+ Connect-MsolService -Credential $Cred

我不知道为什么会失败。我试过了

Import-Module MSOnline -Verbose

我可以看到cmdlet正在加载。我试着创造剖面图.ps1文件位于C:\WINDOWS\system32\WindowsPowerShell\v1.0\位置。在

如果我在本地执行代码,一切正常。我试着运行一个常规的.ps1文件'磁盘.ps1'而不是我的代码,这很好,因为它不加载任何模块:

get-WmiObject win32_logicaldisk -Computername $env:computername

有什么解决方法可以让带模块的脚本正常运行?stdout总是空的。在

节点注册为64位,因此我尝试将cmd更改为

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe 

我试着模仿剖面图.ps1在那里,复制了模块,但仍然不能通过rundeck工作。在


Tags: 模块代码脚本cmd节点windowsexesubprocess
1条回答
网友
1楼 · 发布于 2024-05-15 02:31:55

根据您的描述,由于您能够在直接从服务器运行脚本时获得有效的输出,因此您的错误可能与您用于登录MS Online的“Second Hop”有关。目前,Rundeck Python-Winrm plugin支持Basic、ntlm或CredSSP身份验证,CredSSP身份验证允许您成功执行第二跳。在

相关问题 更多 >

    热门问题