Also, if you're going to be working with ADSI, WMI, and Perl, buy Dave Roth's book, Win32 Perl Scripting: The Administrator's Handbook. It has a lot of useful examples. My only complaint? I wish the book came with a CD of the examples.
-----Original Message----- From: Rick Tatem [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 01, 2002 1:27 PM To: Rick Tatem; [EMAIL PROTECTED] Subject: RE: creating Win2k users with perl All of this assumes that you have permissions to do so. These run under your current security context. Otherwise, you just have to authenticate when getting the initial container object. Sometimes that requires a different method (and maybe an extra step or two) but there's plenty of examples out there, so I'll leave that as an exercise. ;) Rick -----Original Message----- From: Rick Tatem Sent: Thursday, August 01, 2002 4:02 PM To: [EMAIL PROTECTED] Subject: RE: creating Win2k users with perl I've always used ADSI via the Win32::OLE (and Win32::OLE::Enum when needed) module(s). You can take just about any VBScript example (widely available... just Google for 'em) and convert to Perl. In the most general terms: Open the "container" object using GetObject Call the 'Create' method of the container, telling it what objectClass to create (user,contact,group,organizationalUnit,etc.) With the newly created object, Put attributes into place End w/SetInfo. Here's an example using the LDAP NameSpace: use Win32::OLE; my $Name = "First Last"; my $ID = "filast"; # # "Users is the usual container, but you can select any OU you might have defined # my $Container = Win32::OLE->GetObject("LDAP://CN=Users,DC=domain,DC=com"); my $NewUser = $Container->Create("user","CN=" . $Name); $NewUser->Put("sAMAccountName",$ID); # If you don't Put 512 into userAccountControl, the new account will be disabled $NewUser->Put("userAccountControl",512); #keep ->Putting attribute values as needed... # $NewUser->SetInfo; #Commit change Here's one using the WinNT NameSpace (Also works for NT4 domains if ADSI 2.5 is installed) But this example, I'll precede it by the VBScript version (to see how easy the "translation" is) VBScript ---------- ' comment to make the line numbers match :) Set oDomain = GetObject("WinNT://Domain") Set oUser = oDomain.Create("user", "jdoe") oUser.SetInfo ---------- Perl ---------- use Win32::OLE; my $Domain = Win32::OLE->GetObject("WinNT://Domain"); my $User = $Domain->Create("user, "jdoe"); $User->SetInfo; ---------- Add some '$' in front of variables, change "." to "->" and you've got a Perl script! There's plenty of info available as to what attributes are required/optional. I mainly deal with EXISTING accounts, although I do create new Groups/Distribution Lists alot. Basically the same tasks. But These examples are the bare bones. Once you get into leveraging the existing VBScript codebase, you can do a lot more (at least _I_ have) w/the Perl translation. List (ARRAY) manipulation, string operations, regexes are all much easier (in my admittedly biased opinion) in perl. But why re-invent the wheel when you can just hitch a ride with the DLLs that are already goin' your way? Just make them more useful. Rick --- Rick Tatem Messaging and Directory Resources SAS Institute SAS... The Power To Know (tm) _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs