Modify default dynamic object ttl (VBScript)

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 VBScript code from this site.

' This VBScript code modifies the default TTL setting for dynamic objects in a forest

' ---------------------------------------------------------------
' From 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 ------
strNewValue   = 172800

'Could be DynamicObjectMinTTL instead if you wanted to set that instead
strTTLSetting = "DynamicObjectDefaultTTL" 
' ------ END CONFIGURATION ---------

const ADS_PROPERTY_APPEND = 3
const ADS_PROPERTY_DELETE = 4

set objRootDSE = GetObject("LDAP://RootDSE")
set objDS = GetObject("LDAP://CN=Directory Service,CN=Windows NT," & _ 
                      "CN=Services,CN=Configuration," & _
                      objRootDSE.Get("rootDomainNamingContext")
for each strVal in objDS.Get("msDS-Other-Settings")
   Set objRegEx = New RegExp   
   objRegEx.Pattern = strTTLSetting & "="
   objRegEx.IgnoreCase = True
   Set colMatches = objRegEx.Execute(strVal)
   For Each objMatch in colMatches
      Wscript.Echo "Deleting " & strVal
      objDS.PutEx ADS_PROPERTY_DELETE, "msDS-Other-Settings", Array(strVal)
      objDS.SetInfo
   Next
Next

Wscript.Echo "Setting " & strTTLSetting & "=" & strNewValue
objDS.PutEx ADS_PROPERTY_APPEND, _
            "msDS-Other-Settings", _
            Array(strTTLSetting & "=" & strNewValue)
objDS.SetInfo

This code has been viewed 1467 times.

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