南瓜园

 找回密码
 注册
查看: 1062|回复: 0

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

[复制链接]
发表于 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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

QQ|小黑屋|手机版|Archiver|南瓜园

GMT+8, 2024-11-18 13:41 , Processed in 0.121141 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表