【发布时间】:2023-04-06 21:37:02
【问题描述】:
我正在解析有关 Windows 系统上用户帐户更改的日志消息。 我想通知用户有关更改,因此我需要检索他们的个人信息 来自 Active Directory 的信息(First、Last、E-Mail)。
我已经找到了检索用户名的方法,但只能通过 WMI 而不是 ADSI:
Function FindUser(Message)
Dim objWMIService
Dim strAccountRegex
Dim objRegex
Dim objMatch
Dim strComputer
Dim objUser
Dim objShell
strAccountRegex = "(\%\{[A-Z,0-9,\-]*\})"
strComputer = "."
Wscript.StdOut.writeLine "Querying WMI to retrieve user-data"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShell = WScript.CreateObject("WScript.Shell")
Set objRegex = new RegExp
objRegex.Pattern= strAccountRegex
for each objMatch in objRegex.Execute(Message)
REM Wscript.StdOut.writeLine "Found an Account ID: " & objMatch.value
Dim strSID
strSID=NormalizeSID(objMatch.value)
REM Wscript.Echo "SID after escaping: " & strSID
Set objUser = objWMIService.Get _
("Win32_SID.SID='" & strSID & "'")
next
FindUser=objUser.ReferencedDomainName & "\" & objUser.AccountName
End Function
它工作正常,但我想通过 Active Directory 而不是通过 WMI 来完成。 你能帮帮我吗?
【问题讨论】:
标签: windows vbscript active-directory adsi