gpt4 book ai didi

python - Pywinrm 和 Active Directory PowerShell cmdlet

转载 作者:太空宇宙 更新时间:2023-11-04 05:02:50 24 4
gpt4 key购买 nike

我使用 pywinrm 模块的 Python 代码遇到了一个奇怪的问题。让我解释一下。我有一个 Linux 服务器,我在其中启动以下 python 脚本:

import winrm

"""Create security group"""
s = winrm.Session('https://servername:5986/wsman',
auth=(None, None), transport='kerberos',
server_cert_validation='ignore')

name = "test"
path = "OU=Security Groups,DC=test,DC=org"

ps_command = 'New-ADGroup -Name "{0}"
-GroupScope Universal
-GroupCategory Security
-Path "{1}" -Server ldap.test.org'.format(name, path)

r = s.run_ps(ps_command)

if r.status_code == 0 :
print(r.std_out.decode('UTF-8'))
else:
print(r.std_err('UTF-8'))

这将连接到 Windows 服务器(不是 DC)的 HTTPS 监听器,然后将启动组创建命令。

当我直接在 Windows 服务器上启动 AD cmdlet 时,它运行良好,并且在 AD 中创建了安全组。但是通过脚本,我得到以下响应:

$ python3 test_winrm.py
New-ADGroup : Unable to contact the server. This may be because this server does not exist, it is currently down,
or it does not have the Active Directory Web Services running.
At line:1 char:1
+ New-ADGroup -Name "test" -GroupScope Universal -GroupCategory Security
-Path "O ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-ADGroup], ADServer
DownException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirector
y.Management.Commands.NewADGroup

我还想注意到,如果我将当前的 PowerShell 命令替换为基本命令(例如,在 Windows 服务器上创建文件夹),它会起作用。

因此即使安装了 RSAT,它也可以在本地 Windows 服务器上运行,但不能与 AD cmdlet 一起使用...您以前是否有过这方面的经验?

感谢您的帮助。

最佳答案

非常感谢@BenH 的帮助,您对我的问题的根源是正确的,经过几天/头痛之后,我终于在这里找到了解决方案:https://github.com/diyan/pywinrm/issues/58 .使用 kerberos 和 pywinrm 时,必须设置 kerberos_delegation=True 以支持多跳。

关于python - Pywinrm 和 Active Directory PowerShell cmdlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45306504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com