域中计算机与用户,枚举域内所有用户和计算机的脚本

枚举域内所有用户

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值