Show sender restrictions (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 script hides the selected object from all address lists

# This code displays the sender restrictions on a group object.
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

use constant cdoexmAccept => 0;
# Included senders
use constant cdoexmReject => 1;
# Excluded senders
$strGroupDN = '<GroupParentDN>';
# e.g. cn=Staff,dc=3sharp,dc=com
# ------ END CONFIGURATION ------

# Prepare the address list array
my @arrAddress;
$intSize = 0;

# Create the group object
$objGroup = Win32::OLE->GetObject('LDAP://' . $strGroupDN);
print 'Sender restrictions for ' . $objGroup->Name . '.', "\n";

# Is the address list empty? If so, there are no restrictions.
# If not, determine the type and enumerate using a dynamic array since we
# do not know how many items there are in it.
if (!($objGroup->RestrictedAddressList)) {
    print "There are no sender restrictions on this group.\n";
}
else {
    if ($objGroup->RestrictedAddresses == cdoexmAccept) {
        print "The following senders can send to the group:\n";
    }
    else {
        print "The following senders cannot send to the group:\n";
    }
    foreach my $strAddress (in $objGroup->RestrictedAddressList) {
        my @arrAddress;
        $arrAddress[$intSize] = $strAddress;
        print "$arrAddress[$intSize]\n";
        $intSize = $intSize + 1;
    }
}

This code has been viewed 625 times.

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