#135346 - 2005-03-14 03:55 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
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
|
Top
|
|
|
|
#135348 - 2005-03-14 04:17 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
Ahhh. Ok, I wasn't reading the formula right. Thx.
So in the end, the whole script looks like this. Code:
$ou = GetUserOU() $SS = Split(Split($ou,',DC=')[0],',OU=')[1] $SS1 = Left($SS,Instr($SS,' ')-1) $SSLeft = Right($SS,Len($SS)-Instr($SS,' ')) SET "SITE="+$SSLeft SET "REGION="+$SS1
Function GetUserOU() Redim $TempArray[0] Redim $GetUserOU $adSys = CreateObject("ADSystemInfo") $TempArray = Split($adSys.UserName,",") If Right($TempArray[0],1) = "\" $Start = 2 Else $Start = 1 EndIf
For $Counter = $Start To UBound($TempArray) If Len($GetUserOU) = 0 $GetUserOu = $TempArray[$Counter] Else $GetUserOu = $GetUserOu + "," + $TempArray[$Counter]
EndIf Next
$adSys = 0 EndFunction GetUserOU()
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?
|
Top
|
|
|
|
#135350 - 2005-03-14 04:50 PM
Re: comma delimited string or array question
|
BillRamby
Fresh Scripter
Registered: 2005-03-11
Posts: 10
|
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:
; Get users AD OU data by calling the getuserou function $ou = GetUserOU() ; Take the string and split out the needed part $SS = Split(Split($ou,',DC=')[0],',OU=')[1] ; Take the resulting string and parse left from the first space $SS1 = Left($SS,Instr($SS,' ')-1) ;Take the string and parse right from the first space $SSLeft = Right($SS,Len($SS)-Instr($SS,' ')) ; Set the system variables SET "SITE="+$SSLeft SET "REGION="+$SS1
;Function GetUserOU() ; ;Author Remko Weijnen ; ;Action Returns the DN of the OU/Container which the user is placed in ; ;http://www.kixhelp.com/udfs/udf/112015.htm ; ;Returns If the DN eq CN=SomeUser,OU=SomeOU,DC=ad,DC=local ; it returns OU=SomeOU,dc=ad,dc=local ; ; Function GetUserOU() Redim $TempArray[0] Redim $GetUserOU $adSys = CreateObject("ADSystemInfo") $TempArray = Split($adSys.UserName,",") ; Check if there's a comma in the CN, eg if the user name = "Surname, Name" AD returns "Surname\, Name" If Right($TempArray[0],1) = "\" $Start = 2 Else $Start = 1 EndIf
For $Counter = $Start To UBound($TempArray) If Len($GetUserOU) = 0 $GetUserOu = $TempArray[$Counter] Else $GetUserOu = $GetUserOu + "," + $TempArray[$Counter]
EndIf Next
$adSys = 0 EndFunction GetUserOU()
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 918 anonymous users online.
|
|
|