本文介绍了如何使用Python Pyad模块在Active Directory中创建新用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Active Directory中创建具有不同属性的100 000个用户.我正在尝试使用pyad模块,如下所示:

I am trying to create 100 000 users in Active Directory with different attributes. I am trying this with pyad module as shown below:

from pyad import *


user = aduser.ADUser.from_cn("test")
pyad.set_defaults(ldap_server="blr.test.local", username="Administrator", password="test@123")
ou = ADContainer.from_dn("ou=users, dc=test, dc=local")
new_user = ADUser.create("ADUSER123123", ou, password="Secret123")

但是我遇到了以下错误:

But I am getting below error:

C:\Users\Administrator\Desktop>python ad_create_user.py

Traceback (most recent call last):
  File "ad_create_user.py", line 6, in <module>
    ou = ADContainer.from_dn("ou=users, dc=test, dc=local")
NameError: name 'ADContainer' is not defined

C:\Users\Administrator\Desktop>

我已经安装了pyad模块.我正在Windows Server 2008 R2中尝试此操作.

I have installed pyad module. And I am trying this in Windows server 2008 R2.

推荐答案

我刚遇到此错误,并且我想出了解决方法,请在下面的代码段中查找,以便您进行比较.

I have just had this error and I figured out how to resolve it, please find below the piece of code so you can compare.

from pyad import *

pyad.set_defaults(ldap_server="IT-LHQ-DC1.LIFEALIKE.LAB", username="administrator", password="password")

ou = pyad.adcontainer.ADContainer.from_dn("ou=All_Users, dc=LIFEALIKE, dc=LAB")
new_user = pyad.aduser.ADUser.create("test.02", ou, password="password")

基本上,如果您未将其键入为pyad.adcontainer.ADcontainer.from_dn(...)

Basically, it is not calling correctly the function if you don't type it as pyad.adcontainer.ADcontainer.from_dn(...)

我希望这可以为您提供帮助,并且对您有意义.

I hope this could help you and it make any sense for you.

扫罗

这篇关于如何使用Python Pyad模块在Active Directory中创建新用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 04:36