def create_user(user_settings, password): # Deprecated function ''' Create a Windows Active Directory user with data supplied from a dict and password, q is the adquery object.\n Arguments:\n :param user_settings: User settings created by create_user_setting(user_data) <type:dict>\n :param password: Password for the user to be registerd <type:str> ''' ou_arg = str("OU=" + user_settings["department"] + ",DC=" + userdomain + ",DC=" + domainsuffix) dept = user_settings["department"].upper() '''q = adquery.ADQuery() q.execute_query( attributes=["distinguishedName", "ou", "cn"], where_clause="ou = '{}'".format(dept), base_dn="" ) ou_arg = q.get_single_result().get("distinguishedName")''' pyad.set_defaults(ldap_server=ldap_server, username=username, password=password) ou = adcontainer.ADContainer.from_dn(ou_arg) name = user_settings["sAMAccountName"] user = aduser.ADUser.create(name, ou, password, user_settings) user.set_user_account_control_setting("DONT_EXPIRE_PASSWD", True) return user
def add_to_group(username, password, server, groupdn, cn): from pyad import pyad pyad.set_defaults(ldap_server=server, username=username, password=password) group = pyad.from_dn(groupdn) user = pyad.from_cn(cn) group.add_members([user]) print "Moved " + user + "to " + group
def init(ldap_server, username, password): pyad.set_defaults(ldap_server=ldap_server, username=username, password=password)
usernames = loop_addomain() g = adgroup.ADGroup.from_cn(usergroup).get_members() for user in g: if user.get_attribute("cn", False).lower() == name.lower(): return False #print(str(usernames)) if name in usernames: return False else: return True if __name__ == "__main__": if len(os.sys.argv) == 6: pyad.set_defaults(ldap_server=ldap_server, username=username, password=password) user_data = { 'name': os.sys.argv[1], 'passw': os.sys.argv[2], 'department': os.sys.argv[3], 'role': os.sys.argv[4], 'email': os.sys.argv[5] } #print(user_data['name']) user_data['fname'], user_data['lname'] = split_name( user_data['name'], get_last_index_of(user_data['name'], charachter=" ")) user_settings = create_user_settings(user_data) sAMAccountName = get_username(user_data['fname'], user_data['lname']) ou = adcontainer.ADContainer.from_dn(
firstName = (df.iloc[intRow_First, intColumn_First]) lastName = (df.iloc[0, 1]) userName = (df.iloc[0, 2]) group1 = "pldc student" intRow_First += 1 intColumn_First += 0 condition_First += 1 print(firstName) print(lastName) print(userName) user = firstName + "." + lastName print(user) pyad.set_defaults(ldap_server="rti.loc", username="******", password="******") ou = pyad.adcontainer.ADContainer.from_dn( "OU=WLC, OU=1st Battalion, DC=rti, DC=loc") new_user = pyad.aduser.ADUser.create(user, ou, password="******", enable=True) def force_pwd_change_on_login(self): self.update_attribute("PwdLastSet", 0)