【问题标题】:Pywinrm and Active Directory PowerShell cmdletsPywinrm 和 Active Directory PowerShell cmdlet
【发布时间】:2017-12-31 13:39:38
【问题描述】:

我的 Python 代码使用 pywinrm 模块时遇到了一个奇怪的问题。 让我解释一下。我有一个 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 一起使用...您以前有过这个主题的经验吗?

感谢您的帮助。

【问题讨论】:

标签: python powershell active-directory cmdlets kerberos-delegation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多