List delegates (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 lists the delegates, if any, for the selected
# mailbox.
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE;

$strDCName = '<serverName>';
# e.g. "batman"
$strUserName = '/cn=<userName>,<container>,<domainDN>';
# e.g. "/cn=David P. Robichaux, CN=Users, dc=robichaux, dc=net" ' ------ END CONFIGURATION ---------

# find the target user
$strQuery = 'LDAP://' . $strDCName . $strUserName;
$theUser = Win32::OLE->GetObject($strQuery);
print "Mailbox $strUserName\n";

$delegateList = $theUser->Get('publicDelegates');
if ((0 + Win32::OLE::LastError()) != -2147463155) {
    print "has these delegates:\n";
    foreach my $Desc (@{$delegateList}) {
        print "  $desc\n";
    }
}
else {
    print "+ Has no delegates\n";
}

$delegateList = $theUser->Get('publicDelegatesBL');

if ((0 + Win32::OLE::LastError()) != -2147463155) {
    print "+ is a delegate of\n";
    foreach my $Desc (@{$delegateList}) {
        print "  $desc\n";
    }
}
else {
    print "+ Not a delegate for anyone\n";
}

This code has been viewed 916 times.

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