Create mail enabled group (Perl)

This code can be found in Chapter 5 of Exchange Server Cookbook

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 script was originally published in the Exchange Cookbook,
# (http://www.exchangebookcook.com). Written by Paul Robichaux, 
# Missy Koslosky, and Devin Ganger. Redistributed with permission 
# of the publisher, O'Reilly & Associates.

# This code creates a new mail-enabled group of the specified
# type. You have to specify the container and group name.

# ------ SCRIPT CONFIGURATION ------

use Win32::OLE;

$strDCName = '<ServerName>';
# e.g. CONT-EXBE01
$strContainer = '<containerName>';
# e.g. "/CN=Users, dc=contoso, dc=local"
$strGroupName = '<groupName>';
# e.g. "Led Zeppelin Fans" 
use constant ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP => 4;
use constant ADS_GROUP_TYPE_GLOBAL_GROUP => 2;
use constant ADS_GROUP_TYPE_LOCAL_GROUP => 4;
use constant ADS_GROUP_TYPE_SECURITY_ENABLED => -2147483648;
use constant ADS_GROUP_TYPE_UNIVERSAL_GROUP => 8;
# ------ END CONFIGURATION ---------

$objContainer = Win32::OLE->GetObject('LDAP://' . $strDCName . $strContainer);
$objGroup = $objContainer->Create('Group', 'cn=' . $strGroupName);
$objGroup->Put('sAMAccountName', $strGroupName);
$objGroup->Put('groupType', ADS_GROUP_TYPE_UNIVERSAL_GROUP);
$objGroup->MailEnable();
$objGroup->SetInfo();
print "New group $strGroupName created successfully\n";

This code has been viewed 903 times.

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