VbScript: GetStores
A VbScript function to retrieve all Exchange Information Stores from Active Directory, returning the results as a Dictionary object containing the store name and store distinguishedName.
Function GetStores
' Return Type: Scripting.Dictionary
'
' Finds all Private Information Stores in AD
Const ADS_SCOPE_SUBTREE = 2
Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Dim objCommand : Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
Dim objRootDSE : Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, distinguishedName " & _
"FROM 'LDAP://" & objRootDSE.Get("configurationNamingContext") & _
"' WHERE objectClass='msExchPrivateMDB'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Dim objRecordSet : Set objRecordSet = objCommand.Execute
Dim objStores : Set objStores = CreateObject("Scripting.Dictionary")
While Not objRecordSet.EOF
Dim strDN : strDN = objRecordSet.Fields("distinguishedName").Value
Dim strName : strName = objRecordSet.Fields("name").Value
objStores.Add strDN, strName
objRecordSet.MoveNext
WEnd
Set GetStores = objStores
End Function
Usage example
Set objStores = GetStores For Each strDN in objStores WScript.Echo "DN: " & strDN & vbCrLf & "Name: " & objStores(strDN) Next
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
Posted by Paul on 06.10.08 at 7:50 pm
Nice job, works like a charm. I’ve combined it with some info I pulled from WMI so that I can determine the info-store sizes of a particular server. Thanks for your work!
p.s.
You might want to add an example on how to call the function, for the less advanced vbscripters. I’ll be posting my addition on http://www.servercare.nl in the near future…