Page 1 of 1 1
Topic Options
#136059 - 2005-03-22 06:44 PM AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
Hello, I am trying to do something in KIX that I think will be very simple for you guys, but I am stumped.

Basically, I am trying to compare the OU that a user is in to the OU that the PC he is logging in to is in. The basic premise is that I am trying to create a single logon script that caters to 5 different physical locations. If a user logs in, the script will hopefully check what OU he is in, and what OU the computer resides in. If the user is logging in to a PC from his own OU, then he will run his script, if he logs into a PC from another location, it will run the local script.

Does that make sense to anyone? I did some searching and I was able to find a script that will query AD to determine what OU the computer is in, but I need a little more help with the mechanics of it all.

Short Version:
Check User's OU
Check Computer's OU
Compare
if User's OU = Computer's OU then XYZ
If User's OU |= Computer's OU then ABC

If anyone can help me out with this or point me in the right direction, I would be really appreciate it.

Thanks.
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136060 - 2005-03-22 06:48 PM Re: AD Query
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
How about...

ADSearch() - Search for name or account name in Active Directory

HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#136061 - 2005-03-22 07:02 PM Re: AD Query
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
How about the TranslateName() and InContainer() UDFs?

Edited by Les (2005-03-22 07:03 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#136062 - 2005-03-22 08:30 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
I tried ADSearch and I get no output for some reason.

When I use this:

Code:

Function GetComputerOU()
Redim $TempArray[0]
Redim $GetComputerOU
$adSys = CreateObject("ADSystemInfo")

$TempArray = Split($adSys.ComputerName,",")
; Check if there's a comma in the CN, eg if the user name = "Surname, Name" AD returns "Surname\, Name"

If Right($TempArray[0],1) = "\"
$Start = 2
Else
$Start = 1
EndIf

For $Counter = $Start To UBound($TempArray)
If Len($GetComputerOU) = 0
$GetComputerOu = $TempArray[$Counter]
Else
$GetComputerOu = $GetComputerOu + "," + $TempArray[$Counter]
EndIf
Next

$adSys = 0
EndFunction GetComputerOU()



That I grabbed out of another post here, I get:

Code:

OU=Computers OU,OU=HQ,DC=corp,DC=premcor,DC=tld



The "HQ" is the OU that I am looking for. Unfortunately, I am not 100% with .KIX. I tried everything I could think of to pick that "HQ" out of that but nothing seemed to work.

So if someone could just give me some info on how to get that, as well as do something similar for the User, that would be great.

Thanks!
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136063 - 2005-03-23 01:53 AM Re: AD Query
Mordac85 Offline
Fresh Scripter

Registered: 2000-02-16
Posts: 34
Loc: Urbana, OH, USA
InStr( ) could scan for OU=HQ, but I think Les is right on.
A better alternative would be InContainer(), or if you wanted even more info on the objects, TranslateName()
_________________________
~Glenn

==============================
Deadlines take their toll.
Please have exact change.

Top
#136064 - 2005-03-23 01:25 PM Re: AD Query
Anonymous
Unregistered


Thanks everyone - It looks like InContainer is going to do exactly what I need it to do. Awesome.
Top
#136065 - 2005-03-23 01:26 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
Quote:

Thanks everyone - It looks like InContainer is going to do exactly what I need it to do. Awesome.




Woops. That was me. Thanks again.
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136066 - 2005-03-23 02:14 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
OK - I spoke too soon (probably not, but I need help).

InContainer is working just fine for me EXCEPT, we have several OUs that I am trying to enumerate, all of them have a 2 or 3 character name (HQ, DCR, etc.), except for one that is simply "Memphis". When I run the script below:
Code:

$HQ = InContainer("OU=HQ,DC=corp,DC=premcor,DC=tld","User")
$DCR = InContainer("OU=DCR,DC=corp,DC=premcor,DC=tld","User")
$PAR = InContainer("OU=PAR,DC=corp,DC=premcor,DC=tld","User")
$LIR = InContainer("OU=LIR,DC=corp,DC=premcor,DC=tld","User")
; $MER InContainer("OU=Memphis,DC=corp,DC=premcor,DC=tld","User")
$BIR = InContainer("OU=HQ,OU=BIR,DC=corp,DC=premcor,DC=tld","User")
$HAT = InContainer("OU=HQ,OU=HAT,DC=corp,DC=premcor,DC=tld","User")
$HFR = InContainer("OU=HQ,OU=HFR,DC=corp,DC=premcor,DC=tld","User")

Select
Case $HQ[0]>0 ? "HQ"
Case $DCR[0]>0 ? "DCR"
Case $PAR[0]>0 ? "PAR"
Case $LIR[0]>0 ? "LIR"
Case $MER[0]>0 ? "MER"
Case $BIR[0]>0 ? "BIR"
Case $HAT[0]>0 ? "HAT"
Case $HFR[0]>0 ? "HFR"
EndSelect



It works fine, but if I uncomment the line that contains Memphis, I get:
Code:

ERROR : Error in expression: this type of array not supported in expressions.!



Any ideas on this one? Thanks.
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136067 - 2005-03-23 02:15 PM Re: AD Query
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
if you look at the line:
Code:

; $MER InContainer("OU=Memphis,DC=corp,DC=premcor,DC=tld","User")



long enough you see that it will work fine if changed to:
Code:

$MER = InContainer("OU=Memphis,DC=corp,DC=premcor,DC=tld","User")

_________________________
!

download KiXnet

Top
#136068 - 2005-03-23 02:18 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
Quote:

if you look at the line:
Code:

; $MER InContainer("OU=Memphis,DC=corp,DC=premcor,DC=tld","User")



long enough you see that it will work fine if changed to:
Code:

$MER = InContainer("OU=Memphis,DC=corp,DC=premcor,DC=tld","User")





oh crap

You're right (duh).

Edit: I took out a snotty reply here because I thought he was just pointing out the fact that it was commented...Sorry and thanks.


Edited by oobnuker (2005-03-23 02:19 PM)
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136069 - 2005-03-23 02:23 PM Re: AD Query
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that's exactly why I told LONG enough

k, no harm done
_________________________
!

download KiXnet

Top
#136070 - 2005-04-12 06:48 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
OK folks, I got this script going and everything is working great. My only gripe (not even mine really) is that sometimes there is a delay in getting the info back from AD. I attribute this to what DC the user is logged in to, and just general latency in returning the info from AD. It doesn't always happen, but when it does, the delay is agonizing ( like 10-20 seconds or more - yeah yeah, agonizing ). Any ideas?
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136071 - 2005-04-12 06:58 PM Re: AD Query
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Fix your underlying AD problem. Either your site is not setup right or you have some rogue DNS records.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#136072 - 2005-04-12 07:02 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
That's what I thought. I'll tell the Network Admins that Les said their AD is messed up...
_________________________
-- oobnuker - .KIX hack - no really.

Top
#136073 - 2005-04-12 08:07 PM Re: AD Query
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Also examine the call to the Translatename() UDF. InContainer call translate name like TranslateName (3, "", 3, $Name1, 1) which is binding to the Global Catalog. You could experiment with changing the binding to the domain or even a DC. See the documentation in the TranslateName UDF.

Since you are looking for explicit domain data, binding to the domain may be the best solution for you.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#136074 - 2005-04-13 04:47 PM Re: AD Query
oobnuker Offline
Getting the hang of it

Registered: 2003-12-09
Posts: 87
Loc: Oxford, CT
Quote:

Also examine the call to the Translatename() UDF. InContainer call translate name like TranslateName (3, "", 3, $Name1, 1) which is binding to the Global Catalog. You could experiment with changing the binding to the domain or even a DC. See the documentation in the TranslateName UDF.

Since you are looking for explicit domain data, binding to the domain may be the best solution for you.




Ok - In this code:
Code:

If $Name1 <> ""
$Name2 = TranslateName (2, "@LServer", 3, $Name1, 1)
;$Name2 = TranslateName (3, "", 3, $Name1, 1)



This is a snippet of the InContainer UDF that calls TranslateName. You can see my original code commented out, and what I am trying now. Do you think this will help at all? My thinking is that it will hit whatever DC is authenticating them. Also, @Lserver return \\domaincontrollername - are the \\ going to screw things up or will it figure it out?

Am I making any sense?

Also, some insight into our setup here. We have 5 major physical sites located across the US. For some reason when they went to AD, they decided to go with a single domain. So that domain includes about 2500 computers and 5000 users. I am assuming that this may have something to do with the delay in returning things from AD.

Thanks again for any help.


Edited by oobnuker (2005-04-13 04:50 PM)

Top
#136075 - 2005-04-13 07:35 PM Re: AD Query
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Please also read the end of the Incontainer thread ( http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=82433&an=0&page=0#82433 )

Depending on your usage it could add unnecessary round trips to the AD for each user lookup. Radimus has added another approach that is more network friendly if you are checking to see if a user is in a list of OUs.


As for your sample code you want to remove the "\\" from @lserver - use substr(@lserver, 3).

Your single domain should not be an issue if you have a DC in each major site. You should also investigate to insure the AD sites have been configured with the proper list of subnets. This will keep your AD aware client talking to the closest DC.


Edited by Howard Bullock (2005-04-13 07:35 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 581 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.125 seconds in which 0.073 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org