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

[复制链接]
查看1146 | 回复0 | 2012-4-1 19:27:30 | 显示全部楼层 |阅读模式
显示当前域内所有计算机名称及数目
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
发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则