Page 1 of 1 1
Topic Options
#133618 - 2005-02-10 11:00 PM LDAP Query
Shaun Williams Offline
Lurker

Registered: 2001-12-16
Posts: 2
Loc: Michigan
I'm looking to do the following. I basically want to find out what particular OU a machine is in. I don't want the entire DN name, just the OU that it resides in. Any Ideas? I basically looking to do an

IF Object.ou = something

ENDIF

Top
#133619 - 2005-02-10 11:29 PM Re: LDAP Query
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Well, think there are more than a few UDF's that will handle this, search our UDF library for more information, here's one here:

GetComputerOU() - Retrieve OU of computer account

This returns the OU the computer is in, plus all the DC= DC= blah blah crap, but one can modify this UDF to parse/return just what your after ...

By the way, this UDF doesn't even use an LDAP lookup, it looks-up information already on the machine after one logs-in, through ADSystemInfo. ..

Top
#133620 - 2005-02-11 01:06 AM Re: LDAP Query
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

I don't want the entire DN name, just the OU that it resides in



PFFFTT! This is not Wendy's!

Just take the DN and Split() off what you want. How hard can it be?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133621 - 2005-02-11 03:49 AM Re: LDAP Query
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I have a UDF for that...

read this thread, look at the LdapArray() UDF
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=44380&page=&view=&sb=5&o=&fpart=1&vc=1
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#133622 - 2005-02-11 05:25 AM Re: LDAP Query
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I just use Howard's InContainer() UDF. Since OUs can be nested, I don't really want to know the specific OU the computer is in. You can however specify any depth you want.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133623 - 2005-02-11 08:17 PM Re: LDAP Query
Shaun Williams Offline
Lurker

Registered: 2001-12-16
Posts: 2
Loc: Michigan
Curious to get you opinions on What I have so far. I'm using a UDF and modifying it to Look for a particular OU, and then go to that Section of the script.

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] + Chr(10)
Else
$GetComputerOu = $GetComputerOu + "" + $TempArray[$Counter] + Chr(10)
EndIf
Next
Chr(10)
? "--------------------For Each---------------------" + Chr(10)

For Each $Element In $TempArray
If $Element = "OU=NA1"
? "Whoo Hoo!"
GOTO Brazil
ENDIF
Next



$adSys = 0

Quit

:Troy
? "Entering TROY Script"
GOTO END

:Brazil
? "Entering Brazil"
GOTO END




:END
quit


EndFunction GetComputerOU()

Top
#133624 - 2005-02-11 08:38 PM Re: LDAP Query
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
YUCK!

First off, you should not hack up a UDF and turn it into quasi-inline code.
Second, lose the GOTOs.
Third, how would you call the UDF and pass parms to it?

In your fist post, you said you needed to know what OU a computer is in but it looks to me you are turning it around to see if a computer is in a particular OU. That is not the same thing. What is wrong with just using InContainer() without having to modify anything?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#133625 - 2005-02-12 01:17 AM Re: LDAP Query
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You might also want to read the FAQ Forum on how to use UDFs. They're not meant to be modified.
_________________________
There are two types of vessels, submarines and targets.

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
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.07 seconds in which 0.039 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