Solved

VBScript Needed to query a specific attribute in AD

Posted on 2010-11-10
6
451 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Server 2012 management. 5 57
VB Script: split files based a intlines flag 27 58
get the ALL CAPITAL words from a cell 4 32
Import CSV with All modify groups 17 87
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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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 …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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