当前位置:编程学习 > 网站相关 >>

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

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


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

补充:综合编程 , 安全编程 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,