Sign in to follow this  
Followers 0
gr1fter

display certain text from active directory CN

6 posts in this topic

hopefully this is an easy one:

I have cn of CN=computername,OU=number,OU=name1,OU=name2...etc

how do i display only the second OU=name1? as only name1

example in a messagebox will be fine. I can't figure this one :(

Share this post


Link to post
Share on other sites



Obligatory geeky regexp solution:

#include <Array.au3>

$sDN = "CN=computername,OU=number,OU=name1,OU=name2,DC=Fabrikam,DC=COM"
$aResult = StringRegExp($sDN, "(?U)(?:OU=)(.+)(?:,)", 3)
_ArrayDisplay($aResult, "$aResult")

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

wow that was fast. It does work in your example, but if i put it in a msgbox or a GUICtrlCreateEdit it is blank.

here is what i put:

#include <Array.au3>

$sDN = "CN=computername,OU=number,OU=name1,OU=name2,DC=Fabrikam,DC=COM"
$aResult = StringRegExp($sDN, "(?U)(?:OU=)(.+)(?:,)", 3)
MsgBox (0,"",$aResult)

Share this post


Link to post
Share on other sites

The $aResult is an array. AutoIt arrays are 0-based, so the second entry is $aResult[1].

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

The $aResult is an array. AutoIt arrays are 0-based, so the second entry is $aResult[1].

:(

Thank you very much, i have it working now. As my title states, im still a newbie, but i'm getting there.

If you don't mind can you explain what this part means (?U)(?:OU=)(.+)(?:,). Thanks again.

Share this post


Link to post
Share on other sites

If you don't mind can you explain what this part means (?U)(?:OU=)(.+)(?:,).

It's a "regular expression" pattern (see StringRegExp() in the help file):

"(?U)" = "invert greediness", which means find the smallest possible match vice the largest.

"(?:OU=)" = "?:" means this part is non-capturing, or not to be included in the results, though it part of finding the results. You want stuff AFTER "OU=" without including the string "OU=" in the results.

"(.+)" = one or more of any characters

"(?:,)" = another non-capturing group looking for a comma, but not including it in the result.

So the pattern says to return all characters between "OU=" and ",".

We invert greediness because by default it would return everything between the first "OU=" and the last ",". That would have made the result = "number,OU=name1,OU=name2,DC=Fabrikam" (largest possible match).

Hope that helps.

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0