How do you query the AD to find out machines/servers hosting Exchange.
I know that when we install Exchange in a domain, it goes and puts/registers that machine with certain flag declaring that it has exchange server hosted on it.
How do i query the AD to find out all such machines?
Also If was writing an application/software which would need to mark/edit the AD store for some information, which would help us in taking certain actions based on the flags/marking. Pointers to help / doc would be highly appreciated.
April 9th, 2010 10:05am
Hi,
Is this what are you looking for:
VBScript:
'Function EnumerateXchSvr 'prints all the exchange servers in the forest
'standard ADO, ADSI stuff
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strSchemaNC = objRootDSE.Get("schemaNamingContext")
strExchangeCN = "LDAP://cn=Microsoft Exchange,cn=Services" & "," & strConfigurationNC
strCMDTxt = "Select distinguishedName, name from '" & strExchangeCN & " 'where objectCategory='CN=ms-Exch-Exchange-Server," & strSchemaNC & "'"
objCommand.CommandText = strCMDTxt
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount > 0 Then
objRecordSet.MoveFirst
Else
WScript.Echo "no records found"
WScript.Quit
End If
Do Until objRecordSet.EOF 'build our array
strXchSvr = objRecordSet.Fields("Name").Value
WScript.Echo strXchSvr
objRecordSet.MoveNext
Loop
Note: I have modified script to just print the server names. You can see the actual script here: List Microsoft Exchange Servers
Regards,
Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
Free Windows Admin Tool Kit Click here and download it now
April 9th, 2010 4:37pm