View modify LDAP query policy (Perl)
This code can be found in
Chapter 4 of Active Directory Cookbook, 2nd edition
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 Perl code modifies a setting of the default query policy for a forest
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
# "Active Directory Cookbook" by Robbie Allen
# Publisher: O'Reilly and Associates
# ISBN: 0-596-00466-4
# Book web site: http://rallenhome.com/books/adcookbook/code.html
# ---------------------------------------------------------------
# ------ SCRIPT CONFIGURATION ------
my $pol_attr = "MaxPageSize"; # Set to the name of the setting you want to modify
my $new_value = 1000; # Set to the value of the setting you want modify
# ------ END CONFIGURATION ---------
use Win32::OLE 'in';
$Win32::OLE::Warn = 3;
my $ADS_PROPERTY_APPEND = 3;
my $ADS_PROPERTY_DELETE = 4;
my $rootDSE = Win32::OLE->GetObject("LDAP://RootDSE");
my $ldapPol = Win32::OLE->GetObject("LDAP://cn=Default Query Policy,cn=Query-Policies," .
"cn=Directory Service,cn=Windows NT,cn=Services," .
$rootDSE->Get("configurationNamingContext") );
foreach my $prop (in $ldapPol->GetEx("ldapAdminLimits")) {
if ($prop =~ /$pol_attr\=/) {
if ($prop eq "$pol_attr=$new_value") {
print "$pol_attr already equal to $new_value\n";
}
else {
$ldapPol->PutEx($ADS_PROPERTY_APPEND, "lDAPAdminLimits", ["$pol_attr=$new_value"] );
$ldapPol->SetInfo;
$ldapPol->PutEx($ADS_PROPERTY_DELETE, "lDAPAdminLimits", [$prop]);
$ldapPol->SetInfo;
print "Set $pol_attr to $new_value\n";
}
last;
}
}
|
This code has been viewed 2027 times.
|
New from the creators of TechTasks.com:
StatSheet.com
|