Page 1 of 2 12>
Topic Options
#129108 - 2004-11-08 04:38 PM How to find an OU?
redniels Offline
Fresh Scripter

Registered: 2002-10-21
Posts: 19
Loc: Netherlands
Hi,
Iīm getting a bit frustated..

Recently we got from the stoneage (NT4) to the here and now, with AD2003.
Iīm lost. In my own AD forest.
As you can (or cannot) imagine a lot has changed scriptwise..

anyways: what I want to do is search the domain for a given OU.
i.e. I need the full LDAP path to the OU sales.

I know how to search for groups, Users, even enumerate Ouīs. but how do I find OUīs?

itīs probably childishly easy, but I canīt find it, and now, after a day of searching (here, on MSDN, etc) I give up. please help.



Top
#129109 - 2004-11-08 04:40 PM Re: How to find an OU?
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
DSQuery i belive you find it (amongst other useful commands) in the support tools

and i suggest you get a manual as well, to understand AD better especially if you have gone from NT. Something like the M$ Press book


Edited by AzzerShaw (2004-11-08 04:42 PM)
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#129110 - 2004-11-08 04:51 PM Re: How to find an OU?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Tell you what I do, I wrote a little utility called ASEPathFinder, you can get it here:

ASEPathFinder

Just run it and select which protocol path you want (WinNT or LDAP), then click location and select your domain, then click advanced and you can search your domain ...

At the end of dialog, the "path" is returned into the dialog box, then you can just easy cut-and-paste the string into your script, like this:

$object = createobject("<the string>")

And Bob's your uncle ... is this what you meant by "search for groups" etc ? Or you talking about searching in the script itself ?

-Shawn

Top
#129111 - 2004-11-08 04:54 PM Re: How to find an OU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I cannot imagine for what purpose you would have to search for an OU. Maybe if you explained the purpose, we could suggest a different approach and some existing UDFs that fill the need.

That said, someone posted here a nice KiXform script to browse AD. Unfortunately he did not add his credits to it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129112 - 2004-11-08 04:56 PM Re: How to find an OU?
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
Quote:


anyways: what I want to do is search the domain for a given OU.
i.e. I need the full LDAP path to the OU sales.






Surely dsquery is what you need, it will return back the ldap path?

altho this tree im climbing up could be the wrong one
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#129113 - 2004-11-08 05:04 PM Re: How to find an OU?
redniels Offline
Fresh Scripter

Registered: 2002-10-21
Posts: 19
Loc: Netherlands
fast....
DSquery..
thanks, found that already, but thatīs not what I need.
lets give some more info..
why do I need it:
Iīm trying to create a script which moves users form 1 part of our org to another. letīs say a user is in sales and gets a new job in another department, letīs say HR.

my script(s) (as far as the parts are ready) deletes the user from the sales groups, add him to the HR groups, moves the mailbox to the different Exchange 2003 store, moves his profile to the different profile share (letīs say server\HRprofiles) the same for his homedir.
and the last thing I need to do is move this user from the sales OU to the HR OU. but since our organisation is quite large we have 60+ OUīs. I can create a "table" in my script,
like

if "$newgroup"="HR"
$newou="OU=xyz,OU=XYZ2,OU=HR,DC=company,DC=loc"
endif
(or case select, whatever)

but since this is high maintainance I donīt want it.
I want to search in the AD with KIX for this new OU , and return the full ldap path ... which i can feed to the next command..

Top
#129114 - 2004-11-08 05:13 PM Re: How to find an OU?
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
Quote:


and the last thing I need to do is move this user from the sales OU to the HR OU






before i say dsmove(!?) Why cant you move?

also

Quote:



I want to search in the AD with KIX for this new OU , and return the full ldap path ... which i can feed to the next command..




Im still saying dsquery you can use it within the script....just my opinion


Edited by AzzerShaw (2004-11-08 05:21 PM)
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#129115 - 2004-11-08 05:19 PM Re: How to find an OU?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Unless your OU naming scheme is rock-solid consistent, I would suggest you stick with your original plan ... why not just create an INI file of all your OU's, and give them nicknames like you already have ...

[OU]
HR = "OU=xyz,OU=XYZ2,OU=HR,DC=company,DC=loc"
MTG = "OU=xyz,OU=XYZ2,OU=MTG,DC=company,DC=loc"
ACC = "OU=xyz,OU=XYZ2,OU=ACC,DC=company,DC=loc"

I know this means a bit of maintenance going forward, but I get the feeling that if you just search on portions of the path, that it would be very slow plus you might run into ambiguity one day - I mean like if you had the name HR in two seperate branches, what then ?

-Shawn

Top
#129116 - 2004-11-08 05:21 PM Re: How to find an OU?
redniels Offline
Fresh Scripter

Registered: 2002-10-21
Posts: 19
Loc: Netherlands
damn! youīre really fast, hold up, I canīt type that fast!
If I get the OU with dsquery, I have to pipe it to a text file, to use it in my kixscript..
which I have to open & readline to do anything with it in kix..
or is there a way to put the dsquery output in a kix var? something like
$var1=Shell "%COMSPEC% /C DSquery OU -name HR
cause when I remember this correctly this will only put the exitcode of the shell command in $var1, not the output..

thanks btw..

Top
#129117 - 2004-11-08 05:25 PM Re: How to find an OU?
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
You can even pipe it straight into the next command say dsmove

check out this link for ideas

dsquery_wildcard
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#129118 - 2004-11-08 05:44 PM Re: How to find an OU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I agree that the risk of ambiguity is too great to allow for an under-the-covers search but you could navigate the structure by browsing. Did you try searching for that KiXforms script I mentioned?

Anyway I found it... written by Chris BTW.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=91082&page=&view=&sb=5&o=&fpart=&vc=1&PHPSESSID=
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129119 - 2004-11-08 07:44 PM Re: How to find an OU?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Well if you ask me, but you didn't...but I will say it anyway.

I would create a group in each OU that represents the OU.
Globalgroup "SALES" in the OU=SALES,dc=dc1,dc=domain,dc=com
Globalgroup "Engineering" in the OU=Engineering,dc=dc1,dc=domain,dc=com

1) use TranslateName() UDF to get the DN of the Group.
2) strip off the CN=SALES to get OU DN or bind to the Group object and get "$grp.Parent"
3) you can use TranslateName() to get the DN of the user and like in #2 you have the user's OU

I would explore a script that takes input like move user (user1) from group SALES to group Engineering. You then can implemet the above listed staep to get all the info you need.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#129120 - 2004-11-09 11:14 AM Re: How to find an OU?
redniels Offline
Fresh Scripter

Registered: 2002-10-21
Posts: 19
Loc: Netherlands
Thanks guys, I really appreciate the fast responses. you all gave me some nice ideas to explore.
in response to the ambiguity issue: All ou names in our org are unique, and this wil never change (at least not in the short-medium term) so that should not be an issue.

at this time I have 4 options, & thatīs all I need

1) the INI file (safe but high main.)
2) dsquery ->pipe to text file, open, readline etc. (slow, due to the piping of the file & opening it, but maybe the easiest to implement) (i need the path for other things so I canīt pipe it directly to DSMOVE for instance.)
3) the idea of the groups in OUīs is nice, but is also like 1 high main.
4) maybe the kixforms script includes some nice ideas, lookin in it now.

once again thanks guys..

ps: a lot has changed since kix 3.6x/NT4. It still is quite a culture shock..

ps ps: Iīm well known for my "nasty" (ugly code) kix scripts but if you guys would like I could post the completed code here once itīs ready..

Top
#129121 - 2004-11-09 11:19 AM Re: How to find an OU?
AzzerShaw Offline
Seasoned Scripter
****

Registered: 2003-02-20
Posts: 510
Loc: Cheltenham, England
I think for reference for other admins who are in your predicment it would be good to see what you finally end up deciding.

Good luck
_________________________
If at first you don't succeed, try again. Then quit. There's no use being a damn fool about it. - W.C Fields

Top
#129122 - 2004-11-09 01:59 PM Re: How to find an OU?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Quote:


2) dsquery ->pipe to text file, open, readline etc. (slow, due to the piping of the file & opening it, but maybe the easiest to implement) (i need the path for other things so I canīt pipe it directly to DSMOVE for instance.)





Specifically your comment "slow, due to the piping of the file & opening it," ... I would not dismiss this option on those grounds ... imagine that the piping and reading back in would be very fast. Think the "slow" bit might be in running the dsquery itself. But since I haven't tested it, can't say. dsquery might be very quick.

-Shawn

Top
#129123 - 2004-11-09 08:55 PM Re: How to find an OU?
NTDOC Administrator Online   content
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Hmmm... I suppose one could use the tools supplied

Fire up Active Directory Users and Computers
By default it should locate the Forest and Domain your on.

Then right click FIND
Then in Find drop down list select Organizational Units
Then in the IN: select your Domain or Entire Directory
Then in Named: Type in the name of the OU you want to find.
When it is found Double-Click it then go to OBJECT and it should
display the Canonical name of the object which is the path to that OU

I would assume this is not an on-going task, if so, why do you need to search for an OU so often in script? I'm sure it can be done via KiXtart and ADSI if one really has to, just curious why as I've been doing this for a while now and don't recall having to search for OU that often.


Top
#129124 - 2004-11-09 09:12 PM Re: How to find an OU?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't understand the delete/recreate thingy... we just move users. A simple drag and drop in ADUC. That way they don't lose any of their perms or audit trails.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#129125 - 2004-11-09 09:31 PM Re: How to find an OU?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Not sure why the Group suggestion would be high maintenance. The groups do not need to have any members unless you want them to for applying permissions to some file server. In this case your maintenance is the same since you have to maintain memberships anyway. The intent of the group was simply a place holder in the OU that you would know existed so that if the OU changed names or location you could still find it.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#172400 - 2007-01-04 07:06 PM Re: How to find an OU? [Re: Howard Bullock]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Old thread I know, but I find myself searching for the same thing here.
Even though I'd have to agree with Howard on the best alternative solution, make a group in the OU you're trying to find. However I'm making a script that will be deployed on about 20 networks. I don't wanna make groups on every network. Basically TranslateName has the shortcoming of not being able to find OU's.

Top
#172537 - 2007-01-08 04:06 PM Re: How to find an OU? [Re: Arend_]
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
You might want to give fnLDAPQuery() a try then. This UDF was not published when this post was started.
Top
Page 1 of 2 12>


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

Who's Online
0 registered and 1471 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.149 seconds in which 0.103 seconds were spent on a total of 14 queries. Zlib compression enabled.

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