Create qdg (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.

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

use Win32::OLE;

$strDCName = '<serverName>';
# e.g. "CONT-EXBE01"	
$strContainer = '<container>';
# e.g. "CN=users,dc=robichaux, dc=net"
$strQDGName = '<name>';
# e.g. "Mail Users"
$strDomain = '@<domain>';
# e.g. "@robichaux.net"
$strFilter = '(&(!cn=SystemMailbox{*})(& (mailnickname=*) (| (&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*))) )))';
# ------ END CONFIGURATION ---------
$objContainer = Win32::OLE->GetObject('LDAP://' . $strDCName . '/' . $strContainer);
$objQDG = $objContainer->Create('msExchDynamicDistributionList', 'CN=' . $strQDGName);
$objQDG->Put('msExchDynamicDLFilter', $strFilter);
$objQDG->Put('displayName', $strQDGName);
$objQDG->Put('mailNickname', $strQDGName);
$objQDG->Put('reportToOriginator', 1);
$objQDG->Put('proxyAddresses', 'SMTP:' . $strQDGName . $strDomain);
$objQDG->Put('legacyExchangeDN', '/o=<orgName>/ou=First Administrative Group/cn=Recipients/cn=' . $strQDGName);
# e.g. "/o=First Organization (Exchange)/ou=First Administrative Group/cn=Recipients/cn=" & strQDGName
$objQDG->put('msExchDynamicDLBaseDN', $strContainer);
$objQDG->Put('systemFlags', 1610612736);
$objQDG->SetInfo();
print "Created QDG $strQDGName\n";

This code has been viewed 722 times.

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