|
|
|||||||
I have a comma delimited string or array received from the getuserou UDF. The returned string looks like this: OU=Users,OU=Some Site,DC=somedc,DC=somedc,DC=somedc,DC=some What I need from the string is the second delimited value, "OU=Some Site". From there I need to strip the OU= and further break it down into "Some" and "Site" and assign each to a variable. I've looked at the manual at ASCAN and SPLIT, but can't quite see how to make them do the job I need. Any pointers in the right direction would be appreciated. Regards Bill R. |
||||||||
|
|
|||||||
Code:
Oh ya... Welcome to the board. |
||||||||
|
|
|||||||
If you Split() on ',OU=' then you need not worry about commas elsewhere. |
||||||||
|
|
|||||||
True, but that will not automatically separate the site value from the ",DC=" domain strings. You will then need to worry about commas in the site OU name when parsing it from the DC= string. |
||||||||
|
|
|||||||
Huh? Just do a double Split(Split()) on ',DC=' first and then on ',OU='. How hard can it be? Jooel would have no prob to do it. |
||||||||
|
|
|||||||
$DN = 'OU=Users,OU=Some Site,DC=somedc,DC=somedc,DC=somedc,DC=some' $SS = Split(Split($DN,',DC=')[0],',OU=')[1] $SS ? |
||||||||
|
|
|||||||
It isn't... (PITA time) I guess that works for this particular example. There are many ways to get the goal line. |
||||||||
|
|
|||||||
I like it. This is a better solution as commas do not interfere. |
||||||||
|
|
|||||||
Wow, lot of input over the weekend. I have my work cut out for me. Thanks everyone. Regards Bill |
||||||||
|
|
|||||||
Ok, I want to understand this as well as use it, so I hope you don't mind some teaching. Ok I get this part. Setting the variable Quote: Ok, here you are taking the variable and making it an array (I think) of it's split parts and getting "Ou=Some Site". Does the split start at zero or one? I'm guessing 0 because the second value, which is the one needed, appears to be one here. Quote: Ok, I understand what your doing here. Your taking "OU=Some Site" and stripping off the ",OU=" as represented by the "4", as in counting from left to right ",OU=" equals 4 characters. Quote: Ok, I got this I think. This is splitting "Some Site" into "Some" and "Site" Quote: This seems a repeat of the section above. What am I missing here? Quote: Oh, and one further question. Let say "OU=Some Site" actually looked like this: OU=Region1 Houston Texas And I would need SiteParts[0] and SiteParts[1] to be reflected this way: SiteParts[0] would equal "Region1" SiteParts[1] would equal "Houston Texas" Would the space in "Houston Texas" cause problems? Thanks again for the help. Regards Bill |
||||||||
|
|
|||||||
yes it would. |
||||||||
|
|
|||||||
So, would the answer be to take "$Sitename", do a substr replacing character 8 with a comma, and repeat the process? Regards Bill |
||||||||
|
|
|||||||
First off, it bugs me that you obfuscate the facts and then come back and change the rules after code has beeen supplied to you. Why don't you spell out all the rules up front in the first place? Second, it is Howard's code you chose to adopt and I did not bother to analyze it beyond the first weakness of the comma delimiter. If I knew all the rules, I may answer differently. What different permutations of "some site" can there be and do you always want to peel off only the first part delimited by a space? Without knowing all the rules... you could check UBound($SiteParts2)>1 and Join() back the second and third (or more) elements... or you could use a combination of Instr() and Substr(). |
||||||||
|
|
|||||||
No obfuscation was intended. It just didn't occure to me at the time of my first post. Different AD names in different regions. I personally work in a region that is just one word and that influenced my question. My error. That said, some regions can have up to three words, e.g "New York City", therefore, I need to split the first section from the rest. |
||||||||
|
|
|||||||
Don't mind me... sour grapes cuz you chose Howard's coode and I haven't had my 3rd cup of coffee yet. Code: break on THis is still overly optimistic code. It would break if there are more OUs. For that you should check UBound(). |
||||||||
|
|
|||||||
Les, your code threw me for a moment (the ? after $ SS) but once tried it does appear to work with a lot less code. Using a combination of your and Howards code: Code:
Returns: Region2 New York City New York City Question for you. What does the apostrophe in your code do? Whoops, just figured it out. Early morning and only two cups here so far. |
||||||||
|
|
|||||||
Still the sour grapes... What is wrong with using my code? The part SubStr($SS, 9) will break if you go to Region10 or more! |
||||||||
|
|
|||||||
Nothing wrong with the code. I just didn't see the value expressed when I ran it in a window until I changed $SS ? to ? $SS Actually I'm checking your new code now. I get the results of: SS1 = [Region1] SSLeft = [York City] Working on where "New" went now. |
||||||||
|
|
|||||||
DOH! I should test my code before posting it. |
||||||||
|
|
|||||||
Dang... had to RTFM. $SSLeft = Right($SS,Len($SS)-Instr($SS,' ')) |
||||||||
|
|
|||||||
Works. Now a question so I understand. How did getting the length of $SS and subtracting the space make the difference? Or did I interpret what you did wrong? Regards Bill |
||||||||
|
|
|||||||
You interpreted wrong. Instr() returns the position of the first space it finds. Len()-Instr() determines how much of the Right() side of the string to return. |
||||||||
|
|
|||||||
Ahhh. Ok, I wasn't reading the formula right. Thx. So in the end, the whole script looks like this. Code:
Cool, and many thanks. Just made my job as a Citrix Admin a whole lot easier. hhmm, question about codiquette. Was it ok to remove the remarked out data of the getuserou UDF as supplied, or is it more proper to leave it in? |
||||||||
|
|
|||||||
Etiquette dictates that 2 lines of comment should be included. ! line with the author, and 1 line with the URL. |
||||||||
|
|
|||||||
Actually, I decided to leave more than that and add to it. I just know someone, somehow, sometime, is going to make me revisit this in the future. Code:
|