Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!win32-perl use strict; $|++; use Win32::AdminMisc; use Text::ParseWords; use Win32::NetAdmin qw(UserCreate LocalGroupAddUsers LocalGroupIsMembe +r GroupIsMember); use Win32::Perms; use Win32::OLE; # Add Modules: # perl ppm.pl install http://www.roth.net/perl/packages/win32-perms.pp +d # perl ppm.pl install http://www.roth.net/perl/packages/win32-adminmis +c.ppd # CSV should be: Logon_Name, Full_Name, Primary_Group, Password # # Version: 1.3a # $server is location of Home Dirs my $server = "\\\\DataStore"; my $Dir; my ($logon, $name, $group, $pw, $year); my $flags = "UF_DONT_EXPIRE_PASSWD"; my $ldapdc = "DC=nmh, DC=nmhschool, DC=ORG"; my $validgroups = 'Teacher|Admin|Student'; # Open the CSV file of account info (format listed above) open IN, 'Add-Users.txt' or die "Could not open data file\n"; while (<IN>) { # Check input, escape single quotes, ingore comments, etc next unless ($_); next if (/^$|^#/); s/'/\\'/g; # Parse the line and remove new lines ($logon, $name, $group, $pw) = &quotewords(',', 0, $_); chomp ($logon, $name, $group, $pw); # Sanity checks and some parsing... die "Need valid group\n" unless ($group =~ /$validgroups/i); # Find class year of student from the logon name if ($group =~ /Student/i) { $year = substr($logon, -2); die "Not a valid year for student: $name\n" unless ($year =~ /\d +{2}/); } # %OU is for the final OU placement my %OU = ("admin" => "Admin", "teacher" => "Teachers", "student" => "Students"); # %comment is for the comment field on the user form my %comment = ("admin" => "Staff", "teacher" => "Faculty", "student" => "Class of 20$year"); # %lgroup is the primary Local Group for the user my %lgroup = ("admin" => "Admin", "teacher" => "Teacher", "student" => "Students"); # %homes is the path for the user's Home Directory or Portfolio Dir +ectory my %homes = ("admin" => "AdminHome", "teacher" => "TeacherHome", "student" => "Students20$year", "portfolio" => "Portfolios\\Class20$year"); # For on-screen status of creation progress... print "Comment: " . $comment{lc($group)} . "\n"; # Create the user if it is not a member of "Domain Users" (meaning +it does not exist) unless ( GroupIsMember('ProdDC-NF', "Domain Users", $logon) ) { UserCreate("ProdDC-NF", $logon, "$pw", 0, USER_PRIV_USER, '', "$ +comment{lc($group)}", UF_DONT_EXPIRE_PASSWD, 'default.bat') || print "Did not create user $logon\n"; print "Created User $logon\n"; } # Add the user to their primary local group unless ( LocalGroupIsMember('ProdDC-NF', "$lgroup{lc($group)}", "$l +ogon") ) { LocalGroupAddUsers('ProdDC-NF', "$lgroup{lc($group)}", "$logon") + || print "Could not add $logon to $lgroup{lc($group)}\n"; } # If it's a student, add them to their class year group if ($group =~ /Student/i) { LocalGroupAddUsers('ProdDC-NF', "Users20$year", "$logon") || print "Could not add $logon to Users20$year\n"; } # Set the Full name of the new user Win32::AdminMisc::UserSetMiscAttributes( '', $logon, USER_FULL_NAME => "$name") || print "Could not edit $logon\n"; # If the Home dir does not exist, create and permission it # SetOwner is a program from a product called Quota Advisor to chan +ge ownership of files and folders from the command line unless ( -d "$server\\$homes{lc($group)}\\$logon" ) { mkdir "$server\\$homes{lc($group)}\\$logon"; `cacls "$server\\$homes{lc($group)}\\$logon\" /E /G NMH\\$logon: +F`; system("setowner /f $server\\$homes{lc($group)}\\$logon /o $logo +n"); } # If in the Students group, create and permission the Portfolio if ($group =~ /Student/i) { unless ( -d "$server\\d\$\\$homes{portfolio}\\$logon" ) { mkdir "$server\\d\$\\$homes{portfolio}\\$logon"; `cacls "$server\\d\$\\$homes{portfolio}\\$logon\" /E /G NMH\\ +$logon:F`; system("setowner /f $server\\d\$\\$homes{portfolio}\\$logon / +o $logon"); } } # Use the 3rd party app TSCMD to populate the info on the TS tab # http://systemtools.com/free_frame.htm system("tscmd \\\\ProdDC-NF \"$logon\" TerminalServerProfilePath \" +\\\\CitrixDS\\TSProfiles\$\\$logon\""); system("tscmd \\\\ProdDC-NF \"$logon\" TerminalServerHomeDir \"\\\\ +DataStore\\$homes{lc($group)}\\$logon\""); system("tscmd \\\\ProdDC-NF \"$logon\" TerminalServerHomeDirDrive \ +"H:\""); # Move user from the Users OU to the OU specified by the Group my $oContainer = Win32::OLE->GetObject("LDAP://OU=$OU{lc($group)}, +$ldapdc"); my $oUser = $oContainer->MoveHere("LDAP://CN=$logon, cn=Users, $lda +pdc","CN=$logon"); $oUser->SetInfo(); } close IN;

In reply to AD Account Creation by jds

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found