Modify user - WinNT (Perl)

This code can be found in Chapter 23 of Active Directory, 3rd 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.

# From the book "Active Directory, Third Edition" 
# ISBN: 0-596-10173-2

use Win32::OLE qw(in);

use strict;

my ($objDomain, $objUser);
$objDomain = Win32::OLE->GetObject('WinNT://MYCORP');
$objDomain->{Filter} = ['User'];
# **********************************************************************
# Iterate over each user and set the LoginScript 
# Print an error if one occurs
# **********************************************************************
foreach my $objUser (in $objDomain) {
    $objUser->{LoginScript} = 'login-new.vbs';
    $objUser->SetInfo();

    if ((0 + Win32::OLE::LastError()) != 0) {
        print $objUser->Name . ' error occurred', "\n";
        Win32::OLE::LastError(0);
    }
    else {
        print $objUser->Name . ' modified', "\n";
    }
}

This code has been viewed 897 times.

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