#136059 - 2005-03-22 06:44 PM
AD Query
|
oobnuker
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
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
|
|
Top
|
|
|
|
#136062 - 2005-03-22 08:30 PM
Re: AD Query
|
oobnuker
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
|
|
|
|
#136064 - 2005-03-23 01:25 PM
Re: AD Query
|
Anonymous
Anonymous
Unregistered
|
Thanks everyone - It looks like InContainer is going to do exactly what I need it to do. Awesome.
|
|
Top
|
|
|
|
#136066 - 2005-03-23 02:14 PM
Re: AD Query
|
oobnuker
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
|
|
|
|
#136073 - 2005-04-12 08:07 PM
Re: AD Query
|
Howard Bullock
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.
|
|
Top
|
|
|
|
#136074 - 2005-04-13 04:47 PM
Re: AD Query
|
oobnuker
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
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)
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 581 anonymous users online.
|
|
|