Solved

VBScript Needed to query a specific attribute in AD

Posted on 2010-11-10
6
432 Views
Last Modified: 2012-06-27
I am looking for a VBScript that when executed it will ask for the username to query, and then when executed checks to see if there is any data in the extensionAttribute1 field.  All the script needs to output is Yes this user is registered, if there is data in the field and No this user isn't registered, if no data is in the field.
0
Comment
Question by:seaninman
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34106509
You can use this.
Change
strNetBIOSDomain = "DOMAIN" to your domain


You may also want to add this to the right click menu in ADUC.

http://www.petri.co.il/add_user_account_information_to_dsa.htm

This site is where I got the functio to convert sam name to DN

http://www.rlmueller.net/NameTranslateFAQ.htm#How%20do%20I%20convert%20an%20NT%20name%20to%20a%20Distinguished%20Name
usr = InputBox("Enter UserName","USER")
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
strNetBIOSDomain = "DOMAIN"
strNTName = usr
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
strUserDN = Replace(strUserDN, "/", "\/")
Set objUser = GetObject("LDAP://" & strUserDN) 
WScript.Echo objUser.extensionattribute1

Open in new window

0
 
LVL 4

Author Comment

by:seaninman
ID: 34106588
When I run the script and put a username in, i get a blank box.
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34106655
The attribute was black then

try this one
usr = InputBox("Enter UserName","USER")
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
strNetBIOSDomain = "DOMAIN"
strNTName = usr
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
strUserDN = Replace(strUserDN, "/", "\/")
Set objUser = GetObject("LDAP://" & strUserDN) 
If objUser.extensionattribute1 = "" Then
wscript.echo "extensionattribute1 is blank"
Else
wscript.echo "extensionattribute1 is " & objUser.extensionattribute1
End If

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4

Author Comment

by:seaninman
ID: 34106931
That works however i referenced the incorrect attribute name.  Its the attribute called groupPriority.  I thought all i would need to do is change the name of the attribute in the script, but that didnt work.  I got an error on line 13, Error: Type Mismatch, Code: 800A000D
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 34107030
If that is the attribute name then you should be able too use this.


If that does not work download ADFIND (www.joeware.net)

and run this

adfind -default -f samaccountname=USERNAME

this will dump all AD attribute for the user.
usr = InputBox("Enter UserName","USER")
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1
strNetBIOSDomain = "DOMAIN"
strNTName = usr
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
strUserDN = Replace(strUserDN, "/", "\/")
Set objUser = GetObject("LDAP://" & strUserDN) 
If objUser.groupPriority = "" Then
wscript.echo "groupPriority is blank"
Else
wscript.echo "groupPriority is " & objUser.groupPriority
End If

Open in new window

0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 34110331
groupPriority is not single valued.  Therefore you probably have to handle it like an array in order to get the value.

See the answer here:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26589781.html

... which is about the description field, but the same answer may appy for the groupPriority field.

So try something like:

MsgBox objUser.groupPriority(0)

... on a user that you know one is populated.

On a user that you know one is *not* populated, try this to get the variable type for testing against:

MsgBox TypeName(objUser.groupPriority)

I expect it to be something like Null or Empty


Hope this helps,
Daz.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to create Bar charts 4 86
How can I save all open docs into a given folder 12 117
Message Logon Windows 2012 R2 Server 16 26
Problem to cell option 1 28
Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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