Categories /
Scripting /
VBScript for Windows
Use the script below to get a specific user object from Active Directory using WMI (Windows Management Instrumentation).
The script queries Active Directory using the LDAP protocol and WMI and prints out the first name and surname of the user if the specified user is in the directory.
Option Explicit
Dim strComputer, strUsername, objWMI, colUsers, objUser
strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\directory\LDAP")
strUsername = InputBox("Please type the user name")
Set colUsers = objWMI.ExecQuery("SELECT * FROM ds_user where ds_sAMAccountName = '" & strUsername & "'")
If colUsers.Count > 0 Then
For Each objUser in colUsers
WScript.Echo "First Name: " & objUser.ds_givenName
WScript.Echo "Last Name: " & objUser.ds_sn
Next
Else
WScript.Echo "No users found!"
End If
06-07-2009 by Thomas Møller Nexø
Unique visits since publich date
9218
Comments (2)
Comment on this article