Delete Routing Group (VBScript)

This code can be found in Chapter 7 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 VBScript 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 deletes a routing group if it meets several tests

' ------ SCRIPT CONFIGURATION -----
' Name of the Exchange organization
strExchangeOrg = "<Organization>" ' e.g., ExampleOrg
' Name of the administrative group the routing group is in
strAdminGroup = "<AdminGroup>" ' e.g., SeattleAG
' Name of the routing group the server is in
strRoutingGroup = "<RoutingGroup>" ' e.g., RedmondRG
' Default boolean state; do not change bool
Ready = True
' ------ END CONFIGURATION --------

' Create the routing group object
strConfigDN = GetObject("LDAP://RootDSE").Get("configurationNamingContext")
strRoutingGroupDN = strRoutingGroup & ",CN=Routing Groups,CN=" & _
   strAdminGroup & ",CN=Administrative Groups,CN=" & _
   strExchangeOrg & ",CN=Microsoft Exchange,CN=Services," & _
   strConfigDN
Set objRoutingGroup = GetObject("LDAP://CN=" & strRoutingGroupDN)

' Test for member servers still in the RG; set boolean false if found
objRoutingGroup.GetInfo
numProperties = objRoutingGroup.PropertyCount
For PropCount = 0 To (numProperties-1)
   Set propEntry = objRoutingGroup.Item(PropCount)
   If (propEntry.Name = "msExchRoutingGroupMembersBL") Then
      Wscript.Echo "Member servers found in routing group " &_
         strRoutingGroup & ";"
      Wscript.Echo "  See Recipe 7.10 to move servers to a new RG."
      boolReady = False
   End If
Next

' Test for connectors still in the RG; set boolean false if found
strConnectorsDN = "Connections,CN=" & strRoutingGroupDN
Set objConnectors = GetObject("LDAP://CN=" & strConnectorsDN)
For Each objConnection in objConnectors
   Wscript.Echo "Connector found: " & objConnection.Name
   boolReady = False
Next

' If the boolean is still true, it's safe to delete the RG
If boolReady = True Then
   objRoutingGroup.DeleteObject(0)
   Wscript.Echo "Deleted RG " & strRoutingGroup & "." & VbCrLF
Else
   Wscript.Echo "RG " & strRoutingGroup & " not deleted." & VbCrLF
End If
 

This code has been viewed 1400 times.

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