;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       GetUserOU() 
;; 
;;ACTION         Returns the OU string for the current user 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION	 1.1 - 2008/07/20 
;; 
;;HISTORY        1.0 - 2006/12/06 - Initial Release 
;;               1.1 - 2008/07/20 - Changed return method to properly return element 0 
;; 
;;SYNTAX         GetUserOU(Object) 
;; 
;;PARAMETERS     Object - OPTIONAL - String 
;;               - Specify a particular object ID to return 
;; 
;;REMARKS        Initial development for use in the Universal Login Script 
;; 
;;RETURNS        String - comma-delimited OU list - OU=x,OU=y,DC=dom,DC=local 
;;               or, with Object specified, the specific object without the qualifier 
;;               eg: GetUserOU(1) returns "y" instead of "OU=x,OU=y,DC=dom,DC=local" 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       If GetUserOU(1) = "My Dept OU"  
;;                 Use E: \\server\share 
;;               EndIF 
; 
Function GetUserOU(OPTIONAL $_Object)
 
 
  Dim $_aTemp, $_Work, $_ADSys, $_First, $_I, $_D
 
  $_D = ''
 
  $_ADSys = CreateObject('ADSystemInfo')
  If @ERROR Exit @ERROR EndIf			; exit if error creating object 
  $_aTemp = $_ADSys.UserName
  If @ERROR Exit @ERROR EndIf			; exit if error obtaining data 
 
  ; Handle a "Last, First" situation - just remove the "\," as it won't be needed 
  $_aTemp = Join(Split($_aTemp, '\,'), '')
 
  ; Split the remaining OU and DC components into an array 
  $_aTemp = Split($_aTemp, ',')
 
  ; Return only OU and DC info - build the string 
  For Each $_I in $_aTemp
    If Not InStr($_I, 'CN=')
      $_Work = $_Work + $_D + $_I
      $_D = ','
    EndIf
  Next
 
  ; return the string, or the specific object requested 
  $GetUserOU = $_Work
  If VarType($_Object)
    $GetUserOU = SubStr(Split($_Work, ',')[$_Object], 4)
  EndIf
 
  Exit 0
 
EndFunction