Edited by castaway - added code tags.# rename_user.pl # # use win32; use Win32::AdminMisc; use Win32::NetAdmin; # Define variables $PDC = "MDCRES02"; $Domain = "SILVER"; open (LOG, ">c:\\scripts\\namelog.txt") or die "Could not open permslo +g.txt log file\n"; open (ERROR,">c:\\scripts\\errorusers.txt") or die "count not open err +orusers.txt log file\n"; print LOG "==> opening file namelog.txt\n"; print LOG "==> opening file errorusers.txt\n"; if (open (LIST,"c:\\scripts\\dupaccounts.csv")) { print LOG "==> opening file dupaccounts.csv\n"; while (chomp($list = <LIST>)) { split_input_file(); renameuseraccount(); } }else{ system(cls); $error = " ? Could not open dupaccounts.csv"; print $error; } # ############################## SUBROUTINES #################### +##################### # Split input file # Use the split function to extract user info sub split_input_file { ($Tit_UserAccount, $Sil_UserAccount) = split(/,/,$list); } sub renameuseraccount { system(cls); if (Win32::NetAdmin::UsersExist($PDC,$Sil_UserAccount)) { + print "==> User $Sil_UserAccount exist\n"; print LOG "==> User $Sil_UserAccount exist\n"; if (Win32::AdminMisc::RenameUser($Domain, $Sil_UserAccount +, $Tit_UserAccount)) { print LOG "==> Renamed $Sil_UserAccount to $Tit_UserAc +count\n"; print "==> Renamed $Sil_UserAccount to $Tit_UserAccoun +t\n"; }else{ print LOG "==> Could not rename $Sil_UserAccount\n"; print "==> Could not rename $Sil_UserAccount"; print ERROR "$Sil_UserAccount\n"; } }else{ print LOG "==> the user $Sil_UserAccount does not exist\n" +; print "==> the user $Sil_UserAccount does not exist\n"; + } }
In reply to Re: Re: Renaming User Accounts
by Anonymous Monk
in thread Renaming User Accounts
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |