Create contact (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 contact object

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

use Win32::OLE;

$strDCName = '<serverName>';
# e.g. "batman"	
$strContainer = '<container>';
# e.g. "/CN=Users, dc=robichaux, dc=net"
$strContactName = '<userName>';
# e.g. John Doe"
$strContactAlias = '<alias>';
# e.g. "JDoe"
$strContactProxyAddr = 'SMTP:<proxyAddr>';
# e.g. "SMTP:jahlove@rediffmail.com"

# ------ END CONFIGURATION ---------
$objContainer = Win32::OLE->GetObject('LDAP://' . $strDCName . $strContainer);
$objContact = $objContainer->Create('Contact', 'cn=' . $strContactName);
$objContact->Put('mailNickname', $strContactAlias);
$objContact->Put('displayName', $strContactName);
$objContact->Put('targetAddress', $strContactProxyAddr);
$objContact->Put('systemFlags', 1610612736);
$objContact->SetInfo();
print "Created contact $strContactAlias at $strContactProxyAddr\n";

This code has been viewed 956 times.

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