ES=read_csv('../ES.csv',encoding='big5')foruinlist(ES['Email:']):iftype(u)==float:continueusername_to_find=u.split('@')[0]user=client.user_find(uid=username_to_find)ifuser['count']>0:# Check if user exists
user_info=user['result'][0]ifuser_info.get('ou')=='...部':continue# Modify the user's organizational unit, assuming 'ou' is the correct parameter
try:client.user_mod(a_uid=username_to_find,ou='...部')print(f'Modified user {username_to_find} to move to ...部')exceptExceptionase:print(f'Failed to modify user {username_to_find}: {e}')else:print(f'User {username_to_find} not found.')
舊部門名稱統一
deptDict={"oldname":"newname",...}withopen('all_uid.txt','r')asf:uids=[i.strip('\n')foriinf]foruinuids:username_to_find=uuser=client.user_find(uid=username_to_find)ifuser['count']>0:# Check if user exists
user_info=user['result'][0]try:ou=user_info.get('ou')[0]exceptExceptionase:ou=user_info.get('ou')ifounotindeptDict:continue# Modify the user's organizational unit, assuming 'ou' is the correct parameter
try:client.user_mod(a_uid=username_to_find,ou=deptDict[ou])print(f'Modified user {username_to_find}')exceptExceptionase:print(f'Failed to modify user {username_to_find}: {e}')else:print(f'User {username_to_find} not found.')