Solved

VBScript Needed to query a specific attribute in AD

Posted on 2010-11-10
6
413 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 12

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now