Break on
$countries = "Belgium", "Corporate", "France", "Germany", "Italy", "Spain", "Switzerland", "The Netherlands"
For Each $country in $countries
	$rc = InContainer("OU=" + $country + ",OU=Company_OU,DC=Domain,DC=Domain,DC=Ext", "User", "username_goes_here")
	If $rc[0] = "1" Or $rc[0] = "2"
		? "Yep this user is a member of the exact OU or a sub OU " $country
	Else
		? "Nope user is NOT a member of the exact OU Or a sub OU " $country
	EndIf
Next
Sleep 5
;FUNCTION         InContainer()
;
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION          1.5
;
;DATE             20-Mar-2002
;REVISED          04-Apr-2005
;
;ACTION           Determines if the current NT4 account name type is a member of a specific container (OU, Computers, etc)
;                 in Active Directory
;
;SYNTAX           InContainer ($Container, $NameType)
;
;PARAMETERS       $Container (Required)
;                  -  String value
;                 Dinstinghished name of the container to check. This must be the fully qualified DN to
;                 accurately make a determination.
;
;                 $NameType (Required)
;                  -  String value
;                 "Computer" or "User" are currently the only valid values
;
;REMARKS          This function returns true if the object being checked in the the specified container
;                 or a child container of that specified.
;
;RETURNS          An ARRAY of three values:
;                    InContainer return code
;                      1 = object is a member of the exact container specified.
;                      2 = object is a member of the container hierarchy.
;                      0 = object is not a member of the container hierarchy.
;                     -1 = Invalid input for $NameType
;                     -2 = Error in TranslateName
;                    TranslateName ErrorCode
;                    TranslateName ErrorText
;
;DEPENDENCIES     OS: Active Directory aware client
;                 Other Functions: TranslateName()
;
;EXAMPLES         $rc = InContainer ("OU=test,OU=9826,OU=NCS,OU=Machines,DC=us,DC=tycoelectronics,DC=com", "Computer")
;                 select
;                   case $rc[0]=1  ? "object is a member of the specified container."
;                   case $rc[0]=2  ? "object is a member of a child container lower in the hierarchy."
;                   case $rc[0]=0  ? "object is NOT a member of this container or a child of this container."
;                   case $rc[0]=-1 ? "InContainer() Error - Invalid input for $NameType "
;                   case $rc[0]=-2 ? "TranslateName() Error"
;                   case 1         ? "Unknown return code"
;                 endselect
;
;
Function InContainer($Container, $NameType, $userid)
	Dim $CurrentContainer, $Name1, $Name2, $Found, $commaloc
	
	Select
		Case $NameType = "Computer" $Name1 = @Domain + "\" + @wksta + "$$"
		Case $NameType = "User" $Name1 = @LDomain + "\" + $userid
		;Case $NameType = "User" $Name1 = @LDomain + "\" + @UserID
		Case 1 $Name1 = ""
	EndSelect
	
	If $Name1 <> ""
		$Name2 = TranslateName(3, "", 3, $Name1, 1)
		
		If $Name2[1] = 0
			
			$Found = 0
			While $Found = 0
				$commaloc = InStr($Name2[0], ",")
				If $commaloc > 1
					If SubStr($Name2[0], $commaloc - 1, 1) = "\"
						$Name2[0] = SubStr($Name2[0], $commaloc + 1)
					Else
						$Found = 1
						$CurrentContainer = SubStr($Name2[0], $commaloc + 1)
					EndIf
				Else
					$Found = 1
				EndIf
			Loop
			
			Select
				Case $CurrentContainer = $Container $InContainer = 1, $Name2[1], $Name2[2]
				Case InStr($Name2[0], $Container) $InContainer = 2, $Name2[1], $Name2[2]
				Case 1 $InContainer = 0, $Name2[1], $Name2[2]
			EndSelect
		Else
			$InContainer = -2, $Name2[1], $Name2[2]
		EndIf
	Else
		$InContainer = -1, 0, ""
	EndIf
EndFunction
;FUNCTION         TranslateName()
;
;AUTHOR           Howard A. Bullock (hbullock@tycoelectronics.com)
;
;VERSION          2.0
;
;ACTION           Translates from one name type to another. Good for converting an NT4 name
;                 like domain\user into an LDAP distinguished name or the reverse.
;
;SYNTAX           TranslateName ($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
;
;PARAMETERS       $InitType (Required)
;                  -  Integer value
;                     1 = ADS_NAME_INITTYPE_DOMAIN
;                     Initializes a NameTranslate object by setting the domain that the object will bind to.
;
;                     2 = ADS_NAME_INITTYPE_SERVER
;                     Initializes a NameTranslate object by setting the server that the object will bind to.
;
;                     3 = ADS_NAME_INITTYPE_GC
;                     Initializes a NameTranslate object by locating the global catalog to which the object
;                     will bind.
;
;                 $BindName (Required)
;                  -  String value
;                     If an $InitType = 3 (ADS_NAME_INITTYPE_GC), then the $BindName = "".
;                     InitTypes 1 and 2 require a name of a domain or server to be input. 
;                     Note: "" may default to the current server or domain.
;
;                 $LookupNameType (Required)
;                  -  Integer value
;
;                 $LookupName (Required)
;                  -  String value see below
;
;                 $ReturnNameType (Required)
;                  -  Integer value see below
;
;                  Documentation of Name Types. Lookup the more info on http://MSDN.Microsoft.com
;                  Not all name types work. "1", "2", and "3" have been the most useful. 
;
;                 1 = ADS_NAME_TYPE_1779
;                 Name format as specified in RFC 1779. For example, "CN=Jane Doe,CN=users, DC=Microsoft, DC=com".
;
;                 2 = ADS_NAME_TYPE_CANONICAL
;                    Canonical name format. For example, "Microsoft.com/Users/Jane Doe".
;
;                 3 = ADS_NAME_TYPE_NT4
;                 Account name format used in Microsoft® Windows© NT® 4.0. For example, "Microsoft\JaneDoe".
;
;                 4 = ADS_NAME_TYPE_DISPLAY
;                 Display name format. For example, "Jane Doe".
;
;                 5 = ADS_NAME_TYPE_DOMAIN_SIMPLE
;                 Simple domain name format. For example, "JaneDoe@Microsoft.com".
;
;                 6 = ADS_NAME_TYPE_ENTERPRISE_SIMPLE
;                 Simple enterprise name format. For example, "JaneDoe@Microsoft.com".
;
;                 7 = ADS_NAME_TYPE_GUID
;                 Global Unique Identifier format. For example, {95ee9fff-3436-11d1-b2b0-d15ae3ac8436}.
;
;                 8 = ADS_NAME_TYPE_UNKNOWN
;                 Unknown name type. The system will try to make the best guess.
;
;                 9 = ADS_NAME_TYPE_USER_PRINCIPAL_NAME
;                 User principal name format. For example, "JaneDoe@Fabrikam.com".
;
;                 10 = ADS_NAME_TYPE_CANONICAL_EX
;                 Extended canonical name format. For example, "Microsoft.com/Users Jane Doe".
;
;                 11 = ADS_NAME_TYPE_SERVICE_PRINCIPAL_NAME
;                 Service principal name format. For example, "www/www.microsoft.com@microsoft.com"
;
;                 12 = ADS_NAME_TYPE_SID_OR_SID_HISTORY_NAME
;                 A SID string, as defined in the Security Descriptor Definition Language (SDDL), for either
;                 the SID of the current object or one from the object's SID history.
;                 For example, "O:AOG:DAD:(A;;RPWPCCDCLCSWRCWDWOGA;;;S-1-0-0)" For more information see
;                 Security Descriptor String Format under "Security" in the Microsoft Platform SDK documentation.
;
;REMARKS          Not name types seem to work.
;
;RETURNS          This function returns an ARRAY of three values:
;                               Name of the type specified by $ReturnNameType (String)
;                               Error number (Long Integer)
;                               Error text (String).
;
;DEPENDENCIES     OS: Active Directory aware client
;
;EXAMPLES         $DN = TranslateName (3, "", 3, "@Domain\@wksta$", 1)
;                 ? "DN = " + $DN[0]
;                 ? "Error = " + $DN[1]
;                 ? "ErrorText = " + $DN[2]
;
;                 $DN = TranslateName (3, "", 3, "@LDomain\@userid", 1)
;                 ? "DN = " + $DN[0]
;                 ? "Error = " + $DN[1]
;                 ? "ErrorText = " + $DN[2]
;
;
Function TranslateName($InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType)
	
	Dim $InitType, $BindName, $LookupNameType, $LookupName, $ReturnNameType
	Dim $NameTranslate, $ReturnName, $Error, $ErrorText
	
	$Error = 0
	$ErrorText = ""
	$ReturnName = ""
	$NameTranslate = CreateObject("NameTranslate")
	$Error = @error
	$ErrorText = @serror
	If $Error = 0
		$NameTranslate.Init($InitType, $BindName)
		$Error = @error
		$ErrorText = @serror
		If $Error = 0
			$NameTranslate.Set($LookupNameType, $LookupName)
			$Error = @error
			$ErrorText = @serror
			If $Error = 0
				$ReturnName = $NameTranslate.Get($ReturnNameType)
				$Error = @error
				$ErrorText = @serror
			EndIf
		EndIf
	EndIf
	$TranslateName = $ReturnName, $Error, $ErrorText
EndFunction