|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
parsing DN for OU that is not parent object of user
OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ Typcial user is: CN=Test,OU=ZZZ,OU=AAA,OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ Running a report and targeting all users in the "BBB" OU. Problem is that I need to grab the name of the "AAA" OU for each user as it pertains to their department (more accurate than what is on user object). No matter how deep the search goes I need the name of the OU the user is in directly below BBB. Yes, some are directly below others are one to four OUs below BBB. I know this involves parsing the user's DN and grabbing the AAA value just totally at a loss for the syntax. BBB will be consistent in the script so I just need to grab what is always directly to the left of it and trim. This is apart of a large script that dumps various user properties like last logon, account expiration etc.... through ADO. Thanks
Show quote
"Sport" <keith.matth***@gmail.com> wrote in message Presumably your ADO query will find all users located "in" other OU's within news:1178056140.809056.41220@o5g2000hsb.googlegroups.com... > Script target is: > OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ > Typcial user is: > CN=Test,OU=ZZZ,OU=AAA,OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ > > Running a report and targeting all users in the "BBB" OU. > > Problem is that I need to grab the name of the "AAA" OU for each user > as it pertains to their department (more accurate than what is on user > object). No matter how deep the search goes I need the name of the OU > the user is in directly below BBB. Yes, some are directly below > others are one to four OUs below BBB. > > I know this involves parsing the user's DN and grabbing the AAA value > just totally at a loss for the syntax. BBB will be consistent in the > script so I just need to grab what is always directly to the left of > it and trim. > > This is apart of a large script that dumps various user properties > like last logon, account expiration etc.... through ADO. the BBB OU. Rather than parsing the string representation to find the departmental OU, I would recommend using the .parent property recursively (or just repetitively) until you get to the BBB OU; then the previous parent will be the OU you are looking for. A few caveats and questions, though... - What if users exist directly in the BBB OU itself? these will not be associated with any departmental OU. By the logic I suggest above, your code might determine that they are their own department. - Because the simple "name" of an OU is not necessarily unique, you should recognize the "BBB" OU by its full distinguished name. I am curious as to the need for such an apparently complex OU structure, for example, we define our "departmental" affiliations using security groups, using OU's only to assign administrative access as required. You might, perhaps, have a different set of account admins for each departmental OU, but then what is the need for even further nesting? If BBB is the parent of the departmental OU's what does it represent, and what would its parent represent (and its parent's parent etc.)? /Al I assume the "base" of your ADO query is:
OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ The only solution I can think of is similar to (watch line wrapping): ========== strBase = ",OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ" strUserDN = "CN=Test,OU=ZZZ,OU=AAA,OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ" k = InStr(UCase(strUserDN), UCase(strBase)) strLeft = Left(strUserDN, k - 1) k = InStr(StrReverse(strLeft), ",") strOU = Right(strLeft, k - 1) Wscript.Echo strOU ========= strOU will be "OU=AAA". If you don't want the "OU=", then use: strOU = Right(strLeft, k - 4) Show quote "Sport" <keith.matth***@gmail.com> wrote in message news:1178056140.809056.41220@o5g2000hsb.googlegroups.com... > Script target is: > OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ > Typcial user is: > CN=Test,OU=ZZZ,OU=AAA,OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ > > Running a report and targeting all users in the "BBB" OU. > > Problem is that I need to grab the name of the "AAA" OU for each user > as it pertains to their department (more accurate than what is on user > object). No matter how deep the search goes I need the name of the OU > the user is in directly below BBB. Yes, some are directly below > others are one to four OUs below BBB. > > I know this involves parsing the user's DN and grabbing the AAA value > just totally at a loss for the syntax. BBB will be consistent in the > script so I just need to grab what is always directly to the left of > it and trim. > > This is apart of a large script that dumps various user properties > like last logon, account expiration etc.... through ADO. > > Thanks > Thanks Richard,
I'm very close with the below, first run I came out with k of 23 and second k of 1 so strSubOU was "". What am I missing? strUserDN = objItem.Get("distinguishedName") strBase = strExtraOU & strDNSDomain k = InStr(UCase(strUserDN), UCase(strBase)) strLeft = Left(strUserDN, k - 1) k = InStr(StrReverse(strLeft), ",") strSubOU = Right(strLeft, k + 4) On May 1, 9:02 pm, "Richard Mueller [MVP]" <rlmueller- nos...@ameritech.nospam.net> wrote: Show quote > I assume the "base" of your ADO query is: > > OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ > > The only solution I can think of is similar to (watch line wrapping): > ========== > strBase = ",OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ" > strUserDN = > "CN=Test,OU=ZZZ,OU=AAA,OU=BBB,OU=CCC,OU=DDD,OU=EEE,DC=FFF,DC=GGG,DC=HHH,DC=III,DC=JJJ" > k = InStr(UCase(strUserDN), UCase(strBase)) > strLeft = Left(strUserDN, k - 1) > k = InStr(StrReverse(strLeft), ",") > strOU = Right(strLeft, k - 1) > Wscript.Echo strOU > ========= > strOU will be "OU=AAA". If you don't want the "OU=", then use: > > strOU = Right(strLeft, k - 4) > > -- > Richard Mueller > Microsoft MVP Scripting and ADSI > Hilltop Lab -http://www.rlmueller.net |
|||||||||||||||||||||||