没有水的鱼 发表于 2010-7-19 00:47:10

显示当前域内所有计算机名称及数目

Const ADS_SCOPE_SUBTREE = 2
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = ObjRootDSE.Get("defaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT * FROM ’LDAP://" & strDomain & "’ WHERE objectCategory=’computer’"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst   
Do Until objRecordSet.EOF   
Wscript.Echo objRecordSet.Fields("ADsPath").Value   
objRecordSet.MoveNext   
Loop
Wscript.Echo ""
Wscript.Echo "Total Computer: "&objRecordSet.RecordCount
显示当前域内所有用户名称及数目
Const ADS_SCOPE_SUBTREE = 2
Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = ObjRootDSE.Get("defaultNamingContext")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT * FROM ’LDAP://" & strDomain & "’ WHERE objectCategory=’user’"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst   
Do Until objRecordSet.EOF   
Wscript.Echo objRecordSet.Fields("ADsPath").Value   
objRecordSet.MoveNext   
Loop
Wscript.Echo ""
Wscript.Echo "Total User: "&objRecordSet.RecordCount
页: [1]
查看完整版本: 显示当前域内所有计算机名称及数目

请大家牢记南瓜园网址 www.nan2008.com