• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

need a script to prompt for user ID and display user info

hello,

im trying to create a script that will prompt for a user ID (ex: ABC123) and then displays related AD info about that user.

ie: prompts for userID --> ABC123

Displays:

Full Name: James Smith
OU=TechUser
PhoneNumber: 555-1212
email: james.smith@email.com
manager's name: Sandra Williams
manager email: sandra.williams@email.com

etc.

I found this scripot but cant seem to get it working .. ie: wont prompt for a userID

On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")

' Currently logged in User
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
 ' or specific user:
 'Set objUser = GetObject("LDAP://CN=johndoe,OU=Users,DC=ss64,DC=com")

WScript.Echo "DN: " & objUser.distinguishedName

WScript.Echo ""
WScript.Echo "GENERAL"
WScript.Echo "First name: " & objUser.givenName
'WScript.Echo "First name: " & objUser.FirstName
WScript.Echo "Initials: " & objUser.initials
WScript.Echo "Last name: " & objUser.sn
'WScript.Echo "Last name: " & objUser.LastName
WScript.Echo "Display name: " & objUser.displayName
'WScript.Echo "Display name: " & objUser.FullName
WScript.Echo "Description: " & objUser.description
WScript.Echo "Office: " & objUser.physicalDeliveryOfficeName
WScript.Echo "Telephone number: " & objUser.telephoneNumber
WScript.Echo "Other Telephone numbers: " & objUser.otherTelephone
WScript.Echo "Email: " & objUser.mail
' WScript.Echo "Email: " & objUser.EmailAddress
WScript.Echo "Web page: " & objUser.wWWHomePage
WScript.Echo "Other Web pages: " & objUser.url
WScript.Echo ""
WScript.Echo "ADDRESS"
WScript.Echo "Street: " & objUser.streetAddress
WScript.Echo "P.O. Box: " & objUser.postOfficeBox
WScript.Echo "City: " & objUser.l
WScript.Echo "State/province: " & objUser.st
WScript.Echo "Zip/Postal Code: " & objUser.postalCode
WScript.Echo "Country/region: " & objUser.countryCode
'WScript.Echo "Country/region: " & objUser.c    '(ISO 4217)
WScript.Echo ""
WScript.Echo "ACCOUNT"
WScript.Echo "User logon name: " & objUser.userPrincipalName
WScript.Echo "pre-Windows 2000 logon name: " & objUser.sAMAccountName
WScript.Echo "AccountDisabled: " & objUser.AccountDisabled
' WScript.Echo "Account Control #: " & objUser.userAccountControl
WScript.Echo "Logon Hours: " & objUser.logonHours
WScript.Echo "Logon On To (Logon Workstations): " & objUser.userWorkstations
' WScript.Echo "User must change password at next logon: " & objUser.pwdLastSet
WScript.Echo "User cannot change password: " & objUser.userAccountControl
WScript.Echo "Password never expires: " & objUser.userAccountControl
WScript.Echo "Store password using reversible encryption: " & objUser.userAccountControl
' WScript.Echo "Account expires end of (date): " & objUser.accountExpires
WScript.Echo ""
WScript.Echo "PROFILE"
WScript.Echo "Profile path: " & objUser.profilePath
' WScript.Echo "Profile path: " & objUser.Profile
WScript.Echo "Logon script: " & objUser.scriptPath
WScript.Echo "Home folder, local path: " & objUser.homeDirectory
WScript.Echo "Home folder, Connect, Drive: " & objUser.homeDrive
WScript.Echo "Home folder, Connect, To:: " & objUser.homeDirectory
WScript.Echo ""
WScript.Echo "TELEPHONE"
WScript.Echo "Home: " & objUser.homePhone
WScript.Echo "Other Home phone numbers: " & objUser.otherHomePhone
WScript.Echo "Pager: " & objUser.pager
WScript.Echo "Other Pager numbers: " & objUser.otherPager
WScript.Echo "Mobile: " & objUser.mobile
WScript.Echo "Other Mobile numbers: " & objUser.otherMobile
WScript.Echo "Fax: " & objUser.facsimileTelephoneNumber
WScript.Echo "Other Fax numbers: " & objUser.otherFacsimileTelephoneNumber
WScript.Echo "IP phone: " & objUser.ipPhone
WScript.Echo "Other IP phone numbers: " & objUser.otherIpPhone
WScript.Echo "Notes: " & objUser.info
WScript.Echo ""
WScript.Echo "ORGANISATION"
WScript.Echo "Title: " & objUser.title
WScript.Echo "Department: " & objUser.department
WScript.Echo "Company: " & objUser.company
WScript.Echo "Manager: " & objUser.manager

Open in new window


any suggestions?
0
nriddock
Asked:
nriddock
1 Solution
 
LIONKINGCommented:
You could use this function (Link) to capture the username from the commandline and store it in a variable.
Then you could substitute

Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

with

Set objUser = GetObject("LDAP://CN=" & yourVariable & ",OU=Users,DC=ss64,DC=com")

Hope it helps.
0
 
X_layerCommented:
Change start of your scipt from:
On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")

' Currently logged in User
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
 ' or specific user:
 'Set objUser = GetObject("LDAP://CN=johndoe,OU=Users,DC=ss64,DC=com")

Open in new window

to:
On Error Resume Next
Dim UserName, objUser

' Currently logged in User
' Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
' or specific user:
UserName = InputBox("Enter userID","User input","abc123")
Set objUser = GetObject("LDAP://CN=" & UserName & ",OU=Users,DC=ss64,DC=com")

Open in new window

0
 
RobSampsonCommented:
Hi, I've added a search function to the script.  Try this.

Regards,

Rob.

Set objNetwork = CreateObject("WScript.Network")
strUsername = InputBox("Enter user samAccountName:", "samAccountName", objNetwork.Username)
strAdsPath = Get_LDAP_User_Properties("user", "samAccountName", strUsername, "adspath")
If strAdsPath = "" Then
	WScript.Echo "User not found"
	WScript.Quit
End If

Set objUser = GetObject(strAdsPath)

WScript.Echo "DN: " & objUser.distinguishedName

WScript.Echo ""
WScript.Echo "GENERAL"
WScript.Echo "First name: " & objUser.givenName
'WScript.Echo "First name: " & objUser.FirstName
WScript.Echo "Initials: " & objUser.initials
WScript.Echo "Last name: " & objUser.sn
'WScript.Echo "Last name: " & objUser.LastName
WScript.Echo "Display name: " & objUser.displayName
'WScript.Echo "Display name: " & objUser.FullName
WScript.Echo "Description: " & objUser.description
WScript.Echo "Office: " & objUser.physicalDeliveryOfficeName
WScript.Echo "Telephone number: " & objUser.telephoneNumber
WScript.Echo "Other Telephone numbers: " & objUser.otherTelephone
WScript.Echo "Email: " & objUser.mail
' WScript.Echo "Email: " & objUser.EmailAddress
WScript.Echo "Web page: " & objUser.wWWHomePage
WScript.Echo "Other Web pages: " & objUser.url
WScript.Echo ""
WScript.Echo "ADDRESS"
WScript.Echo "Street: " & objUser.streetAddress
WScript.Echo "P.O. Box: " & objUser.postOfficeBox
WScript.Echo "City: " & objUser.l
WScript.Echo "State/province: " & objUser.st
WScript.Echo "Zip/Postal Code: " & objUser.postalCode
WScript.Echo "Country/region: " & objUser.countryCode
'WScript.Echo "Country/region: " & objUser.c    '(ISO 4217)
WScript.Echo ""
WScript.Echo "ACCOUNT"
WScript.Echo "User logon name: " & objUser.userPrincipalName
WScript.Echo "pre-Windows 2000 logon name: " & objUser.sAMAccountName
WScript.Echo "AccountDisabled: " & objUser.AccountDisabled
' WScript.Echo "Account Control #: " & objUser.userAccountControl
WScript.Echo "Logon Hours: " & objUser.logonHours
WScript.Echo "Logon On To (Logon Workstations): " & objUser.userWorkstations
' WScript.Echo "User must change password at next logon: " & objUser.pwdLastSet
WScript.Echo "User cannot change password: " & objUser.userAccountControl
WScript.Echo "Password never expires: " & objUser.userAccountControl
WScript.Echo "Store password using reversible encryption: " & objUser.userAccountControl
' WScript.Echo "Account expires end of (date): " & objUser.accountExpires
WScript.Echo ""
WScript.Echo "PROFILE"
WScript.Echo "Profile path: " & objUser.profilePath
' WScript.Echo "Profile path: " & objUser.Profile
WScript.Echo "Logon script: " & objUser.scriptPath
WScript.Echo "Home folder, local path: " & objUser.homeDirectory
WScript.Echo "Home folder, Connect, Drive: " & objUser.homeDrive
WScript.Echo "Home folder, Connect, To:: " & objUser.homeDirectory
WScript.Echo ""
WScript.Echo "TELEPHONE"
WScript.Echo "Home: " & objUser.homePhone
WScript.Echo "Other Home phone numbers: " & objUser.otherHomePhone
WScript.Echo "Pager: " & objUser.pager
WScript.Echo "Other Pager numbers: " & objUser.otherPager
WScript.Echo "Mobile: " & objUser.mobile
WScript.Echo "Other Mobile numbers: " & objUser.otherMobile
WScript.Echo "Fax: " & objUser.facsimileTelephoneNumber
WScript.Echo "Other Fax numbers: " & objUser.otherFacsimileTelephoneNumber
WScript.Echo "IP phone: " & objUser.ipPhone
WScript.Echo "Other IP phone numbers: " & objUser.otherIpPhone
WScript.Echo "Notes: " & objUser.info
WScript.Echo ""
WScript.Echo "ORGANISATION"
WScript.Echo "Title: " & objUser.title
WScript.Echo "Department: " & objUser.department
WScript.Echo "Company: " & objUser.company
WScript.Echo "Manager: " & objUser.manager

Function Get_LDAP_User_Properties(strObjectType, strSearchField, strObjectToGet, strCommaDelimProps)
	
	If InStr(strObjectToGet, "\") > 0 Then
		arrGroupBits = Split(strObjectToGet, "\")
		strDC = arrGroupBits(0)
		strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")
		strObjectToGet = arrGroupBits(1)
	Else
		Set objRootDSE = GetObject("LDAP://RootDSE")
		strDNSDomain = objRootDSE.Get("defaultNamingContext")
	End If

	strBase = "<LDAP://" & strDNSDomain & ">"
	' Setup ADO objects.
	Set adoCommand = CreateObject("ADODB.Command")
	Set adoConnection = CreateObject("ADODB.Connection")
	adoConnection.Provider = "ADsDSOObject"
	adoConnection.Open "Active Directory Provider"
	adoCommand.ActiveConnection = adoConnection

 
	' Filter on user objects.
	'strFilter = "(&(objectCategory=person)(objectClass=user))"
	strFilter = "(&(objectClass=" & strObjectType & ")(" & strSearchField & "=" & strObjectToGet & "))"

	' Comma delimited list of attribute values to retrieve.
	strAttributes = strCommaDelimProps
	arrProperties = Split(strCommaDelimProps, ",")

	' Construct the LDAP syntax query.
	strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
	adoCommand.CommandText = strQuery
	adoCommand.Properties("Page Size") = 100
	adoCommand.Properties("Timeout") = 30
	adoCommand.Properties("Cache Results") = False

	WScript.Echo ""
	WScript.Echo "Executing " & strQuery
	' Run the query.
	Set adoRecordset = adoCommand.Execute
	' Enumerate the resulting recordset.
	Do Until adoRecordset.EOF
	    ' Retrieve values and display.    
	    For intCount = LBound(arrProperties) To UBound(arrProperties)
	    	If strDetails = "" Then
	    		strDetails = adoRecordset.Fields(intCount).Value
	    	Else
	    		strDetails = strDetails & VbCrLf & adoRecordset.Fields(intCount).Value
	    	End If
	    Next
	    ' Move to the next record in the recordset.
	    adoRecordset.MoveNext
	Loop

	' Clean up.
	adoRecordset.Close
	adoConnection.Close
	Get_LDAP_User_Properties = strDetails

End Function 

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nriddockAuthor Commented:
@RobSampson - This works perfectly!

Is there any way to write multiple variables to one popup as opposed to cycling through each one?

ie:
Name: John Smith
Email: john@smith.com
Phone:555-1212
Manager: Bill Adams
0
 
RobSampsonCommented:
Sure, either run the script from a command prompt (or batch file) using
cscript C:\Scripts\ShowDetail.vbs

or, use this version.

Set objNetwork = CreateObject("WScript.Network")
strUsername = InputBox("Enter user samAccountName:", "samAccountName", objNetwork.Username)
strAdsPath = Get_LDAP_User_Properties("user", "samAccountName", strUsername, "adspath")
If strAdsPath = "" Then
	WScript.Echo "User not found"
	WScript.Quit
End If

Set objUser = GetObject(strAdsPath)

WScript.Echo "DN: " & objUser.distinguishedName

WScript.Echo vbCrLf &_
	"GENERAL" & vbCrLf &_
	"First name: " & objUser.givenName & vbCrLf &_
	"Initials: " & objUser.initials & vbCrLf &_
	"Last name: " & objUser.sn & vbCrLf &_
	"Display name: " & objUser.displayName & vbCrLf &_
	"Description: " & objUser.description & vbCrLf &_
	"Office: " & objUser.physicalDeliveryOfficeName & vbCrLf &_
	"Telephone number: " & objUser.telephoneNumber & vbCrLf &_
	"Other Telephone numbers: " & objUser.otherTelephone & vbCrLf &_
	"Email: " & objUser.mail & vbCrLf &_
	"Web page: " & objUser.wWWHomePage & vbCrLf &_
	"Other Web pages: " & objUser.url & vbCrLf &_
	vbCrLf &_
	"ADDRESS" & vbCrLf &_
	"Street: " & objUser.streetAddress & vbCrLf &_
	"P.O. Box: " & objUser.postOfficeBox & vbCrLf &_
	"City: " & objUser.l & vbCrLf &_
	"State/province: " & objUser.st & vbCrLf &_
	"Zip/Postal Code: " & objUser.postalCode & vbCrLf &_
	"Country/region: " & objUser.countryCode & vbCrLf &_
	vbCrLf &_
	"ACCOUNT" & vbCrLf &_
	"User logon name: " & objUser.userPrincipalName & vbCrLf &_
	"pre-Windows 2000 logon name: " & objUser.sAMAccountName & vbCrLf &_
	"AccountDisabled: " & objUser.AccountDisabled & vbCrLf &_
	"Logon Hours: " & objUser.logonHours & vbCrLf &_
	"Logon On To (Logon Workstations): " & objUser.userWorkstations & vbCrLf &_
	"User cannot change password: " & objUser.userAccountControl & vbCrLf &_
	"Password never expires: " & objUser.userAccountControl & vbCrLf &_
	"Store password using reversible encryption: " & objUser.userAccountControl & vbCrLf &_
	vbCrLf &_
	"PROFILE" & vbCrLf &_
	"Profile path: " & objUser.profilePath & vbCrLf &_
	"Logon script: " & objUser.scriptPath & vbCrLf &_
	"Home folder, local path: " & objUser.homeDirectory & vbCrLf &_
	"Home folder, Connect, Drive: " & objUser.homeDrive & vbCrLf &_
	"Home folder, Connect, To:: " & objUser.homeDirectory & vbCrLf &_
	vbCrLf &_
	"TELEPHONE" & vbCrLf &_
	"Home: " & objUser.homePhone & vbCrLf &_
	"Other Home phone numbers: " & objUser.otherHomePhone & vbCrLf &_
	"Pager: " & objUser.pager & vbCrLf &_
	"Other Pager numbers: " & objUser.otherPager & vbCrLf &_
	"Mobile: " & objUser.mobile & vbCrLf &_
	"Other Mobile numbers: " & objUser.otherMobile & vbCrLf &_
	"Fax: " & objUser.facsimileTelephoneNumber & vbCrLf &_
	"Other Fax numbers: " & objUser.otherFacsimileTelephoneNumber & vbCrLf &_
	"IP phone: " & objUser.ipPhone & vbCrLf &_
	"Other IP phone numbers: " & objUser.otherIpPhone & vbCrLf &_
	"Notes: " & objUser.info & vbCrLf &_
	vbCrLf &_
	"ORGANISATION" & vbCrLf &_
	"Title: " & objUser.title & vbCrLf &_
	"Department: " & objUser.department & vbCrLf &_
	"Company: " & objUser.company & vbCrLf &_
	"Manager: " & objUser.manager

Function Get_LDAP_User_Properties(strObjectType, strSearchField, strObjectToGet, strCommaDelimProps)
	
	If InStr(strObjectToGet, "\") > 0 Then
		arrGroupBits = Split(strObjectToGet, "\")
		strDC = arrGroupBits(0)
		strDNSDomain = strDC & "/" & "DC=" & Replace(Mid(strDC, InStr(strDC, ".") + 1), ".", ",DC=")
		strObjectToGet = arrGroupBits(1)
	Else
		Set objRootDSE = GetObject("LDAP://RootDSE")
		strDNSDomain = objRootDSE.Get("defaultNamingContext")
	End If

	strBase = "<LDAP://" & strDNSDomain & ">"
	' Setup ADO objects.
	Set adoCommand = CreateObject("ADODB.Command")
	Set adoConnection = CreateObject("ADODB.Connection")
	adoConnection.Provider = "ADsDSOObject"
	adoConnection.Open "Active Directory Provider"
	adoCommand.ActiveConnection = adoConnection

 
	' Filter on user objects.
	'strFilter = "(&(objectCategory=person)(objectClass=user))"
	strFilter = "(&(objectClass=" & strObjectType & ")(" & strSearchField & "=" & strObjectToGet & "))"

	' Comma delimited list of attribute values to retrieve.
	strAttributes = strCommaDelimProps
	arrProperties = Split(strCommaDelimProps, ",")

	' Construct the LDAP syntax query.
	strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
	adoCommand.CommandText = strQuery
	adoCommand.Properties("Page Size") = 100
	adoCommand.Properties("Timeout") = 30
	adoCommand.Properties("Cache Results") = False

	WScript.Echo ""
	WScript.Echo "Executing " & strQuery
	' Run the query.
	Set adoRecordset = adoCommand.Execute
	' Enumerate the resulting recordset.
	Do Until adoRecordset.EOF
	    ' Retrieve values and display.    
	    For intCount = LBound(arrProperties) To UBound(arrProperties)
	    	If strDetails = "" Then
	    		strDetails = adoRecordset.Fields(intCount).Value
	    	Else
	    		strDetails = strDetails & VbCrLf & adoRecordset.Fields(intCount).Value
	    	End If
	    Next
	    ' Move to the next record in the recordset.
	    adoRecordset.MoveNext
	Loop

	' Clean up.
	adoRecordset.Close
	adoConnection.Close
	Get_LDAP_User_Properties = strDetails

End Function 

Open in new window


Regards,

Rob.
0
 
nriddockAuthor Commented:
Worked perfectly!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now