切换到宽版
  • 6997阅读
  • 1回复

[求助]使用脚本在活动目录林中列出所有的Exchange服务器 [复制链接]

上一主题 下一主题
 
只看楼主 倒序阅读 0楼  发表于: 2011-03-13
— 本帖被 YOYO 从 Exchange 脚本中心 移动到本区(2015-06-25) —
  • 脚本环境:Visual Basic
  • 适合版本:Exchange 2003
  • 适用平台:
  • 脚本作用:列出所有的Exchange服务器
使用此脚本可以在活动目录林中列出所有相关的Exchange服务器。

arrExServerName = EnumerateXchSvr
For j = 0 To Ubound(arrExServerName)
  strExServerName = arrExServerName(j)
  WScript.Echo strExServerName
Next
Function EnumerateXchSvr
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
ReDim arrXchSvr(0)
i = 0
Do Until objRecordSet.EOF
strXchSvr = objRecordSet.Fields("Name").Value
    arrXchSvr(i) = strXchSvr
    i = i + 1
    redim preserve arrXchSvr(i)
    objRecordSet.MoveNext
Loop
EnumerateXchSvr = arrXchSvr
End Function

分享到
只看该作者 1楼  发表于: 2011-04-13
studying
快速回复
限60 字节
 
上一个 下一个