小编Aus*_*ler的帖子

PyWinrm 持久 PowerShell 会话

有没有人知道是否有一种方法可以使用 PyWinrm 打开持久的 PowerShell 会话,该会话可以维护状态并且可以多次调用?我正在尝试执行以下操作:

#!/bin/python

import winrm

# Initialize some COM object and call a method storing the results
# in $Results and then print $Results to stdout
ps_script = """
$SomeObject = New-Object -ComObject Some.Com.Object
$Results = SomeObject.DoThing
$Results
"""

# Create winrm connection
s = winrm.Session('https://server.domain.local', auth=('username', 'password'), transport='kerberos')

# Call the ps_script - contents of $Results is returned as a string
r = s.run_ps(ps_script)

# Parse the contents of $Results returned from the $Results variable
# …
Run Code Online (Sandbox Code Playgroud)

python powershell winrm

6
推荐指数
1
解决办法
431
查看次数

标签 统计

powershell ×1

python ×1

winrm ×1