0

i finished online course at udemy and now i try some stuff and i need help with pyad, trying to create active directory user in virtual machine (the code also at the machine) looked online and it looks perfect one on one but suddenly i get an error,

error with this code:

from pyad import *

pyad.set_defaults(ldap_server="DC-01-Training.Udemy.training",username="Administrator",password="abc-123")

#test create new user
user = "pyadtest"
ou = pyad.adcontainer.ADContainer.from_dn("ou=Users,dc=Udemy,dc=Training")
new_user = pyad.aduser.ADUser.create(user,ou,password="abc-123")

ERROR:

---------------------------------------------------------------------------
com_error                                 Traceback (most recent call last)
<ipython-input-40-c8119c8ee0d8> in <module>
     17 #test create
     18 user = "pyadtest"
---> 19 ou = pyad.adcontainer.ADContainer.from_dn("ou=Users,dc=Udemy,dc=Training")
     20 new_user = pyad.aduser.ADUser.create(user,ou,password="abc-123")
     21 

C:\ProgramData\Anaconda3\lib\site-packages\pyad\adobject.py in from_dn(cls, distinguished_name, options)
    129     def from_dn(cls, distinguished_name, options={}):
    130         "Generates ADObject based on distinguished name"
--> 131         return cls(distinguished_name, None, options)
    132 
    133     @classmethod

C:\ProgramData\Anaconda3\lib\site-packages\pyad\adobject.py in __init__(self, distinguished_name, adsi_ldap_com_object, options)
     86                             self.default_ldap_port
     87             )
---> 88             self.__set_adsi_obj()
     89         else:
     90             raise Exception("Either a distinguished name or a COM object must be provided to create an ADObject")

C:\ProgramData\Anaconda3\lib\site-packages\pyad\adobject.py in __set_adsi_obj(self)
     51                 if self.default_ssl:
     52                     flag = flag | ADS_AUTHENTICATION_TYPE['ADS_USE_ENCRYPTION']
---> 53             self._ldap_adsi_obj = _ds.OpenDSObject(
     54                     self.__ads_path,
     55                     self.default_username,

C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py in OpenDSObject(self, *args)

com_error: (-2147352567, 'Exception occurred.', (0, 'Active Directory', 'There is no such object on the server.\r\n', None, 0, -2147016656), None)

``

MadneSs
  • 11
  • 1
  • 5

1 Answers1

0

In your code it shows:

ou = pyad.adcontainer.ADContainer.from_dn("ou=Users,dc=Udemy,dc=Training")

where it should be:

ou = pyad.adcontainer.ADContainer.from_dn(ou="Users",dc="Udemy",dc="Training")
balexander1
  • 182
  • 1
  • 1
  • 8
  • well i did like in this post:https://stackoverflow.com/questions/34610505/how-to-create-a-new-user-in-active-directory-using-python-pyad-module but i tryed what you sent and i still get an error: File "", line 19 ou = pyad.adcontainer.ADContainer.from_dn(ou="Users",dc="Udemy",dc="Training") ^ SyntaxError: keyword argument repeated – MadneSs Sep 02 '20 at 16:29
  • I think it is because you assigned dc= twice. You might have to do something else there. – balexander1 Sep 02 '20 at 19:20
  • idid it! i went to the ou attribute and copyed the string: ou = pyad.adcontainer.ADContainer.from_dn("CN=Users,DC=Udemy,DC=training") – MadneSs Sep 02 '20 at 20:41