# 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"; + } }
Edited by castaway - added code tags.

In reply to Re: Re: Renaming User Accounts by Anonymous Monk
in thread Renaming User Accounts by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.