Login | |
|
 |
Finding a User's OU - 6/8/2007 12:44:58 AM
|
|
 |
|
| |
RobertParker
Posts: 24
Score: 2
Joined: 6/8/2007
Status: offline
|
Hey I'm pretty new to VBScript. They gave me a book 1.5 weeks ago at work, and told me I had to learn it. Anyway part of the script that I'm working on right now is a login script. The part I'm having trouble with is finding the User's OU. The scripting guys have a script for doing this here. Use the first script on the page. http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1021.mspx But when I run the script instead of getting a distinguished name like: CN=kenmyer,OU=Finance,DC=fabrikam,DC=com mine looks more like: CN=RobertParker,OU=Users,OU=Location1,OU=HUB,OU=US,DC=xxxxxx,DC=xxxxx I think the OUs are set as follows: Location1 is a subgroup of HUB, which is a subgroup of US, which is a subgroup of USERS The only one I want is the one is the lowest level group: OU=Location1 I started writing some code to try and filter out the wrong OUs, but as our OU setup is very complicated it would be very sloppy to program and any update to AD to could cause the code to break. I stopped doing that and now I am stuck. I'm also pretty new to AD btw. How can I find the lowest OU that a user is in?
|
|
| |
|
|
|
 |
RE: Finding a User's OU - 6/8/2007 2:31:42 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Assuming that you have already gottent eh distinguishedname into a string called sDN, you can use the following: WScript.Echo Split(sDN,",OU=")(1) EDIT: I was stupid the first time, changed the split characters to be ,OU= instead of OU=. This way i don't have to do a replace to get rid of the commas. *sigh* Dumb me.
< Message edited by DiGiTAL.SkReAM -- 6/8/2007 5:03:06 AM >
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Finding a User's OU - 6/8/2007 5:00:03 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
The only time it would break is if there were NO OU='s in the distinguishedname. for example: CN=Username,OU=Users,DC=test,DC=com CN=Username,OU=Users,OU=Test1,OU=Test2,OU=Test1,OU=Test2,OU=Test1,OU=Test2,OU=Test1,OU=Test2,DC=test,DC=com using the code I gave you, both of the above would break down to Users But if it were CN=Username,DC=test,DC=com The code would break, yes. BUT, if you are having usernames in your ROOTDSE, then you have more problems than trying to find their OU....
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
|
|