# This script is going to Add users in AD import datetime import rpyc AD_SERVER_IP = '192.168.1.20' AD_BOT_PORT = 19961 domain_controller = 'DC=pliane, DC=net' users_ou = 'OU=All, OU=siege, {}'.format(domain_controller) social_ou= 'OU=social, {}'.format(domain_controller) def send_command(command): try: connection = rpyc.connect(AD_SERVER_IP,AD_BOT_PORT) connection.root.run_command(command) except Exception as Err: print('Error in send command', str(Err)) def create_user(username, social_id, display_name, active = False): """ #Create New user in AD :param username: :param social_id: :param display_name: :param active: return: """ print(datetime.datetime.now()) if active: disabled = 'no' else: disabled = 'yes' description = "User added by AD BOT on {}".format(datetime.datetime.now()) default_password = 'P@ssw0rd' dn = '" CN = {},{}"'.format(username, users_ou) social = '"cn = all,{}"'\ '"cn =usb Deny,{}"'.format(social_ou, social_ou) command = 'dsadd user'\ '{}'\ '-samid "{}"'\ '-upn "{}"'\ '-display"{}"'\ '-empid "{}"'\ '-desc "{}"'\ '-disabled "{}"'\ '-pwd {}'\ '-pwdneverexpires yes'\ '-mustchpwd yes'\ '-memberof {}'\ 'acctexpires never'\ ''.format( dn, username, username, display_name, social_id, description, disabled, default_password, social) try: print(command) send_command(command) except Exception as Err: print('Error in send command', str(Err)) create_user('allan', 'parts', 'allanjean', active=True)