;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       InOU() 
;; 
;;ACTION         Returns True if the current user or computer is a member of the named OU 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION	 1.1 - 2009/08/12 
;; 
;;HISTORY        1.0 - 2007/11/19 - Initial Release 
;;               1.1 - 2009/08/12 - Added computer match 
;; 
;;SYNTAX         InOU(OU[ , strict][ , computer]) 
;; 
;;PARAMETERS     OU - REQUIRED - String 
;;               - Name of OU/DC to check for membership 
;; 
;;		 Strict - OPTIONAL - Integer 
;;               - Flag forcing strict OU compares if non-zero 
;; 
;;               Computer - OPTIONAL - Integer 
;;               - Flag indicating that a computer check should be performed if non-zero. 
;; 
;;REMARKS        Initial development for use in the Universal Login Script 
;; 
;;RETURNS        Boolean - 1 if is a member, 0 if not 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K, WXP, W2K3 
;; 
;;EXAMPLES       ; Do things if user is in an "Admin Accounts" OU 
;;               If InOU('Admin Accounts') ... 
; 
Function InOU($_OUName, OPTIONAL $_Strict, OPTIONAL $_Computer)
 
  Dim $_ADSys			; AD object pointer 
  Dim $_aTemp			; array to collect data 
  Dim $_Work			; working string 
  Dim $_I			; index var 
  Dim $_D			; delimiter 
 
  $_D = ''
  $_Strict = IIf($_Strict, 'OU', '')
 
  $_ADSys = CreateObject('ADSystemInfo')
  If @ERROR Exit @ERROR EndIf			; exit if error creating object 
 
  ; obtain and split the DN string, taking the CN=last\, first into account 
  If $_Computer
    $_aTemp = Split(Join(Split($_ADSys.ComputerName, '\,'), ''), ',')
  Else
    $_aTemp = Split(Join(Split($_ADSys.UserName, '\,'), ''), ',')
  EndIf
  If @ERROR Exit @ERROR EndIf			; exit if error obtaining data 
 
  ; build the string containing only OU and DC info 
  For Each $_I in $_aTemp
    If Not InStr($_I, 'CN=')
      $_Work = $_Work + $_D + $_I
      $_D = ','
    EndIf
  Next
 
  ; If the OUName exists (properly framed) in the OU List, return 1 
  ; adding a comma to the work string allows the search to be framed by "=" and "," 
  If InStr($_Work + ',', $_Strict + '=' + $_OUName + ',')
    $InOu = 1
  Else 		; if not, return 0 
    $InOu = 0
  EndIF
 
  Exit 0
 
EndFunction