pyad icon indicating copy to clipboard operation
pyad copied to clipboard

AttributeError: module 'pyad' has no attribute 'set_defaults'

Open ghost opened this issue 7 years ago • 2 comments

Hi, I don't work much with AD but I am trying to write a script that reads through a list of mac addresses in a txt file and adds a user with the mac address as teh name and the description set to "PEN_(today's date)"

from pyad import *
import pyad
import datetime
i = datetime.datetime.now()

print ("AddMACsToAD.py\nAlan Raff\n04-18-2017")

print ("Please enter the full path to the list of MAC addresses.")
print ("Note: the MAC addresses MUST be in the following format: xx-xx-xx-xx-xx-xx")

filename = input("FILENAME> ")
macFile = open(filename,"r")

for mac in macFile:
	pyad.set_defaults(ldap_server="DCVM01.testwebsite.com", username="alan", password="testpw") #change credentials

	ou = pyad.adcontainer.ADContainer.from_dn("ou=MAC_VoIP, dc=Internal_Special_devices, dc=UPN, dc=testwebsite, dc=com") #change ou path
	new_user = pyad.aduser.ADUser.create(mac, ou, password="pw123")
	new_user.set_attribute("description", "PEN_%s/%s/%s" % (i.month, i.day, i.year))

I write the code like I think it should be, but I'm getting an error saying that the module doesnt have the attribute "set_defaults" on this line I'm assuming: pyad.set_defaults(ldap_server="DCVM01.testwebsite.com", username="alan", password="testpw") #change credentials

ghost avatar Apr 18 '17 17:04 ghost

You can access to library , find pyad.py then edit this file added more set_defaults from import section .

pvhung1 avatar Jun 08 '17 07:06 pvhung1

This is source of 'init.py'. from future import absolute_import from .adbase import set_defaults as pyad_setdefaults all =["adbase", "adquery", "adsearch", "adobject", "adcomputer",
"adcontainer", "addomain", "adgroup", "aduser", "pyad"]

So, you should use 'pyad_setdefaults' instead of 'set_defaults'.

MarkLei1 avatar Jan 01 '19 11:01 MarkLei1