Create group v2 (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;

use strict;

my ($objDomain, $objGroup, $objComputer);

# Creating a group in a Windows NT domain
$objDomain = Win32::OLE->GetObject('WinNT://MYDOMAIN');
$objGroup = $objDomain->Create('group', 'MyGroup');
$objGroup->SetInfo();

# Creating a local group on a computer or member server

# Valid for Windows NT, Windows 2000 and Windows Server 2003
$objComputer = Win32::OLE->GetObject('WinNT://MYCOMPUTER');
$objGroup = $objComputer->Create('group', 'My Group');
$objGroup->SetInfo();

# Creating a group in Active Directory
$objDomain = Win32::OLE->GetObject('LDAP://cn=Users,dc=mycorp,dc=com');
$objGroup = $objDomain->Create('group', 'cn=My Group');
$objGroup->Put('sAMAccountName', 'MyGroup');
$objGroup->SetInfo();

This code has been viewed 1198 times.

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