我无法使用 ldap3 库管理 AD 服务器组策略。
例如,我正在添加New-GPLink策略。我试图添加一个属性[New-GPLink:[LinkEnabled]]
,但得到一个错误。
请用 ldap3 向我建议以下几点:
- 如何在 AD 服务器中添加组策略
- 如何删除 AD 服务器中的组策略
- 如何在 AD 服务器中修改组策略
- 是否可以使用 ldap3 库来安排安装和卸载操作
试过的东西:
- 添加连接
- 搜索用户
- 添加 GroupPolicy 属性。
代码 :
from ldap3 import Server, Connection, ALL, ALL_OPERATIONAL_ATTRIBUTES, ALL_ATTRIBUTES, ObjectDef, Reader
server = Server("192.168.1.28", get_info=ALL)
admin_username = 'lab\\administrator'
admin_password = 'A1B1C1$'
conn = Connection(server, user=admin_username, password=admin_password, auto_bind=True)
search_base = 'dc=lab,dc=com'
search_filter = '(userPrincipalName=shakti@lab.com)'
conn.bind()
conn.search(search_base=search_base, search_filter=search_filter, attributes=attributes_groups)
new_attribute = 'New-GPLink'
d_n = 'CN=shakti,DC=lab,DC=com'
conn.add(dn=d_n,object_class='user',attributes=new_attribute)
低于错误
TypeError Traceback (most recent call last)
<ipython-input-292-425b72018c42> in <module>
----> 1 conn.add(dn=d_n,object_class='user',attributes=new_attribute)
c:\users\ankit.g\appdata\local\programs\python\python36\lib\site-packages\ldap3\core\connection.py in add(self, dn, object_class, attributes, controls)
910
911 attr_object_class = [to_unicode(object_class) for object_class in attr_object_class] # converts objectclass to unicode in case of bytes value
--> 912 _attributes[object_class_attr_name] = reduce(lambda x, y: x + [y] if y not in x else x, parm_object_class + attr_object_class, []) # remove duplicate ObjectClasses
913
914 if not _attributes[object_class_attr_name]:
TypeError: 'str' object does not support item assignment