Link to home
Start Free TrialLog in
Avatar of seaninman
seaninmanFlag for United States of America

asked on

VBScript Needed to query a specific attribute in AD

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.
Avatar of KenMcF
KenMcF
Flag of United States of America image

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

Avatar of seaninman

ASKER

When I run the script and put a username in, i get a blank box.
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

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
ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Darren Collins
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:

https://www.experts-exchange.com/questions/26589781/Query-Active-Directory-Computer-Description-with-VBScript-LDAP.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.