枚举域内所有用户
dim i
Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
'Open the connection with the ADSI-OLEDB provider name
con.Provider = "ADsDSOObject"
con.Open
set objfso = createobject("scripting.filesystemobject")
set objfile = objfso.createtextfile("c:\adusers.txt")
Set objRootDSE = GetObject("")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Com.ActiveConnection = con
Com.CommandText = ";" & "(objectClass=user);SamAccountName;subTree"
wscript.echo " Your domain is " & stradspath
Set rs = Com.Execute()
i=0
Do Until rs.EOF
if right(rs.Fields("samAccountName"),1)<>"$" then
sResultText = sResultText & rs.Fields("SamAccountName") & ","& vbCrLf
i=i+1
end if
rs.movenext
Loop
WScript.Echo sResultText
objfile.writeline sresulttext
objfile.writeline (" there are ") &i& (" users in your domain")
wscript.echo "There are "&i&" users in your domain"
wscript.echo "the output result write to c:\adusers.txt"
con.close
枚举计算机到文件
dim i
Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
'Open the connection with the ADSI-OLEDB provider name
con.Provider = "ADsDSOObject"
con.Open
set objfso = createobject("scripting.filesystemobject")
set objfile = objfso.createtextfile("c:\acomputers.txt")
Set objRootDSE = GetObject("")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Set objDomain = GetObject(strADsPath)
Com.ActiveConnection = con
Com.CommandText = ";" & "(objectClass=computer);SamAccountName;subTree"
wscript.echo " Your domain is " & stradspath
Set rs = Com.Execute()
i=0
Do Until rs.EOF
sResultText = sResultText & rs.Fields("SamAccountName") & ","& vbCrLf
rs.MoveNext
i=i+1
Loop
WScript.Echo sResultText
objfile.writeline sresulttext
objfile.writeline (" there are ") &i& (" computers in your domain")
wscript.echo "There are "&i&" computers in your domain"
wscript.echo "the output result write to c:\acomputers.txt"
con.close