Solved

VBScript Needed to query a specific attribute in AD

Posted on 2010-11-10
6
454 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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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