Page 2 of 2 <12
Topic Options
#135346 - 2005-03-14 03:55 PM Re: comma delimited string or array question
BillRamby Offline
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
#135347 - 2005-03-14 03:59 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135348 - 2005-03-14 04:17 PM Re: comma delimited string or array question
BillRamby Offline
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
#135349 - 2005-03-14 04:22 PM Re: comma delimited string or array question
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Etiquette dictates that 2 lines of comment should be included. ! line with the author, and 1 line with the URL.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135350 - 2005-03-14 04:50 PM Re: comma delimited string or array question
BillRamby Offline
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
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.055 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org