用命令查看整个AD域用户目前正在登录的计算机名

用命令查看整个AD域用户目前正在登录的计算机名,可以在域控制器上新建一个VBS文件,并将以下内容拷贝进去,然后运行该脚本文件,查看那些域用户登录在域中的那台客户端上。

‘ Script for getting current logged user name on Domain
‘ Author : mwpq
‘ www.sharecenter.net
strDomainName = InputBox (“Please enter the internal Domain Name:”,”Script for getting current logged username”,”yourdomain.local”)
arrDomLevels = Split(strDomainName, “.”)
strADsPath = “dc=” & Join(arrDomLevels, “,dc=”)

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject(“ADODB.Connection”)
Set objcommand = CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”‘

Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
“Select Name, Location from ‘LDAP://”&strADsPath&”‘ ” _
& “Where objectClass=’computer’”
objCommand.Properties(“Page Size”) = 1000
objCommand.Properties(“Searchscope”) = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Set oFSO = CreateObject(“Scripting.FilesystemObject”)
Set of = oFSO.CreateTextFile(“LoggedUser.txt”, True, True)

Do Until objRecordSet.EOF
On Error Resume Next
sPC = objRecordSet.Fields(“Name”).Value
of.writeline ” ”
of.writeline “Machine Name: “&sPC

Set objWMILocator = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & sPC & “\root\cimv2″)

If Err = 0 Then

Set col = objWMILocator.ExecQuery _
(“Select * from win32_computersystem”)

For Each item In col

of.writeline “Logged User: “&item.username

Next
Set col = Nothing
Else
of.writeline “!!! Cant connect to “&sPC&” !!!”

End If

objRecordSet.MoveNext
Loop

of.close
MsgBox “Done! Cheers!”


你可能感兴趣的:(AD相关资料)