Modify multiple users (Perl)

This code can be found in Chapter 6 of Active Directory Cookbook, 2nd edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Perl code from this site.

# This Perl code sets the home drive of all users under a container
# to be on a file server where the share name is the same as the user's
# sAMAccountName.

# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
#      "Active Directory Cookbook" by Robbie Allen
# ISBN: 0-596-00466-4
# ---------------------------------------------------------------
use Win32::OLE 'in';
$Win32::OLE::Warn = 3;
my $objParent = Win32::OLE->GetObject("LDAP://<ParentDN>");
$objParent->{Filter} = ["user"];
foreach my $objUser (in $objParent) {
    print "Modifying ", $objUser->Get("sAMAccountName"),"\n";
    $objUser->{HomeDirectory} = "\\\\<FileServerName>\\" .
                                $objUser->Get("sAMAccountName");
    $objUser->SetInfo;
}

This code has been viewed 1855 times.

New from the creators of TechTasks.com: StatSheet.com