?
Solved

VBScript to pull AD info

Posted on 2012-09-12
13
Medium Priority
?
1,884 Views
Last Modified: 2012-09-12
I am creating a script in vbscript to pull user info from our active directory which will ultimately create a users Outlook signature. Everything is going well for the most part, however I can't seem to pull the extension attributes (extensionAttribute1 & 2). The script is pretty basic and I think I am just referencing the attributes wrong but can't figure out how they should be referenced. My code is below. Any help would be great.

'Setup Signature
Set objSysInfo = CreateObject("ADSystemInfo")

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

strName = objUser.FullName
strLic = objUser.extensionattribute2
strTitle = objUser.Title
strDepartment = objUser.Department
strCompany = objUser.Company
strPhone = objUser.telephoneNumber
strExt = objUser.extensionattribute1
strWebpage = objuser.wWWHomePage
strFax = objuser.facsimileTelephoneNumber
strStreet = objuser.streetAddress
strPOBox = objuser.postOfficeBox
strCity = objuser.l
strZip = objuser.postalCode
strState = objuser.st
strMobile = objuser.mobile
wdColorBlue = 16711680 
wdColorBlack = 0

Set objWord = CreateObject("Word.Application")

Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection

Set objEmailOptions = objWord.EmailOptions
Set objSignatureObject = objEmailOptions.EmailSignature

Set objSignatureEntries = objSignatureObject.EmailSignatureEntries

objSelection.Font.Size = "9.0"
objSelection.Font.Name = "Calibri"
objSelection.Font.Color = wdColorBlack

If strName <> "" Then
	objSelection.TypeText strName
		If strLic <> "" Then
			objSelection.TypeText = ", " & strLic
		End If
	objSelection.TypeText(Chr(11))	
End If

objSelection.TypeText = ", " & strLic
objSelection.TypeText(Chr(11))
objSelection.TypeText = ", " & strExt
objSelection.TypeText(Chr(11))

If strTitle <> "" OR strTitle <> "Per Diem" OR strTitle <> "Delta-T" Then
	objSelection.TypeText strTitle
	objSelection.TypeText(Chr(11))
End If

If strDepartment <> "Administration" OR strDepartment <> "Per Diem" OR strDepartment <> "Delta-T" Then
	objSelection.TypeText strDepartment
	objSelection.TypeText(Chr(11))
End if

objSelection.Font.Bold = true
objSelection.TypeText strCompany
objSelection.Font.Bold = False
objSelection.TypeText(Chr(11))

If strDepartment <> "Per Diem" OR strDepartment <> "Delta-T" Then
	objSelection.TypeText strStreet
		If strPOBox <> "" Then
			objSelection.TypeText " P.O. Box " & strPOBox
		End If
	
	objSelection.TypeText(Chr(11))
	objSelection.TypeText strCity & ", " & strState & " " & strZip
	objSelection.TypeText(Chr(11))
	
	If strPhone <> "" Then
		objSelection.TypeText "Office: " & strPhone 
			If strExt <> "" Then
				objSelection.TypeText =" x" & strExt
			End If
		objSelection.TypeText(Chr(11))	
	End If
	
	If strFax <> "" Then
		objSelection.TypeText "Fax: " & strFax
		objSelection.TypeText(Chr(11))
	End If
	
	If strMobile <> "" Then
		objSelection.TypeText "Mobile: " & strMobile
		objSelection.TypeText(Chr(11))
	End if
End if

Open in new window

0
Comment
Question by:mascoloj
  • 8
  • 5
13 Comments
 
LVL 24

Expert Comment

by:yo_bee
ID: 38391384
You might need to try this method.

StrExtAtt1 = objuser.get("extensionAttribute1")
StrExtAtt2 = objuser.get("extensionAttribute2")

Open in new window

0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38391391
strName = objUser.FullName
strLic = objUser.get("extensionattribute2")
strTitle = objUser.Title
strDepartment = objUser.Department
strCompany = objUser.Company
strPhone = objUser.telephoneNumber
strExt = objUser.get("extensionattribute1")
strWebpage = objuser.wWWHomePage
strFax = objuser.facsimileTelephoneNumber
strStreet = objuser.streetAddress
strPOBox = objuser.postOfficeBox
strCity = objuser.l
strZip = objuser.postalCode
strState = objuser.st
strMobile = objuser.mobile
wdColorBlue = 16711680 
wdColorBlack = 0

Open in new window

0
 

Author Comment

by:mascoloj
ID: 38391429
I just tried it but it didn't work.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 24

Expert Comment

by:yo_bee
ID: 38391446
Ok.
Let's see what other means we can try.
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38391494
are you getting an error?
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38391507
I did just notice something with your script.
The attribute name is case sensitive.
You have: objUser.extensionattribute2
When is should be: objUser.extensionAttribute2
0
 

Author Comment

by:mascoloj
ID: 38391558
Your right. I think I have something else going on though which is odd. I set one of the variables to a text string and then stated to print out the string and thats not working either so for all I know, the variable is filling with the attribute information but I would never know because it's not printing out on my screen. here's what I did..

strLic = "Test"
objSelection.TypeText = strLic

The word test never shows up in my signature.
0
 
LVL 24

Accepted Solution

by:
yo_bee earned 2000 total points
ID: 38391586
I like to use  the Msgbox method when testing to see how a string looks.
0
 

Author Comment

by:mascoloj
ID: 38391634
You're brilliant. OK, it IS pulling the right information, it's just not printing it to the screen for some reason.
0
 

Author Comment

by:mascoloj
ID: 38391716
Apparently I have been an idiot on many levels today. Is it Monday? yo_bee - you get the points. Thanks for all your help.
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38391733
What was the cause?
0
 

Author Comment

by:mascoloj
ID: 38391744
I had
objSelection.TypeText = strLic

Open in new window

which should have been
objSelection.TypeText strLic

Open in new window

. The = sign was my issue!
0
 
LVL 24

Expert Comment

by:yo_bee
ID: 38391767
that would do it.
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question