Quantcast
Channel: Ivanti User Community: Message List
Viewing all articles
Browse latest Browse all 12704

Re: How do I query the department column in Active Directory?

$
0
0

I have a VBS script that I patched together from a couple of MS threads to add the LDAP values I needed to the HKCU key in the registry.  I then added a custom reg scan to capture the values to the Custom Data section of my inventory.

It also sets the user's name & initials into MS Office - it is in the startup folder:

 

On Error Resume Next

Dim objSysInfo, objUser

Set objSysInfo = CreateObject("ADSystemInfo")

 

' Currently logged in User

strUser = objSysInfo.UserName

Set objUser = GetObject("LDAP://" & strUser)

Set objWord = CreateObject("Word.Application")

 

' Create a WSH Shell object:

Set wshShell = CreateObject( "WScript.Shell" )

 

' Create a new HKCU\JHL_LDAP_Info key & set variables

wshShell.RegWrite "HKCU\COMPANY_LDAP_Info\", ""

firstname = objUser.givenname

lastname = objUser.sn

department = objUser.department

office = objUser.physicalDeliveryOfficeName

title = objUser.title

 

' Create new string values in that new subkey:

wshShell.RegWrite "HKCU\COMPANY_LDAP_Info\" & "FirstName", firstname, "REG_SZ"

wshShell.RegWrite "HKCU\COMPANY_LDAP_Info\" & "LastName", lastname, "REG_SZ"

wshShell.RegWrite "HKCU\COMPANY_LDAP_Info\" & "Department", department, "REG_SZ"

wshShell.RegWrite "HKCU\COMPANY_LDAP_Info\" & "Title", title, "REG_SZ"

wshShell.RegWrite "HKCU\COMPANY_LDAP_Info\" & "Office", office, "REG_SZ"

 

' Set Office Name & Initials

' There are two methods below to write the user info. The first (and active) is a combination of GiveName and SN

' The second is the same, but it capitalizes the first character and sets the rest to lowercase for when

' your AD environment does not use capitalization for those two fields.  Switch the comment tags around to

' enable the 2nd one.

 

objWord.UserName = objUser.givenName & " " & objUser.SN

 

' objWord.UserName = Ucase(Left(objUser.givenName, 1)) & Lcase(Right(objUser.givenName, Len(objUser.givenName) – 1)) & " " & Ucase(Left(objUser.SN, 1)) & Lcase(Right(objUser.SN, Len(objUser.SN) – 1))

 

objWord.UserInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1)

' objWord.UserInitials = Ucase(Left(objUser.givenName, 1)) & Ucase(Left(objUser.SN, 1))

 

objWord.Quit


Viewing all articles
Browse latest Browse all 12704

Trending Articles