How-to: List a users First and Last name from Active Directory

List a users First and Last name when called with a Distinguished Name.

'uname.vbs

' Display First and Last name for a given DN

On Error Resume Next
Dim  objUser, strDN

strDN = WScript.Arguments.Item(0)
Set objUser = GetObject("LDAP://" & strDN)
WScript.Echo "First name: " & objUser.givenName
WScript.Echo "Last name: " & objUser.sn
WScript.Echo "Display name: " & objUser.displayName

Examples

cscript //Nologo uname.vbs "CN=johndoe,OU=Users,DC=ss64,DC=com"

“I was advised by an American agent when I was about 19 to change my surname” ~ Rachel Weisz

Related VBScript commands

UserInfo - List User properties (as shown in ADUC).


 
Copyright © 1999-2024 SS64.com
Some rights reserved