Something like this should do.
You should change this part OU=test,OU=9826,OU=NCS,OU=Machines,DC=us,DC=tycoelectronics,DC=com to match your situation. The user to query is now set to the user the script runs on by the first line of code below.
Code:
$User = @USERID
$rc = InContainer ("OU=test,OU=9826,OU=NCS,OU=Machines,DC=us,DC=tycoelectronics,DC=com", $User)
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
;Do NOT midify anything below this line!
;
;FUNCTION InContainer()
Function InContainer ($Container, $NameType)
Dim $CurrentContainer, $Name1, $Name2, $Found, $commaloc
Select
Case $NameType = "Computer" $Name1 = @Domain + "\" + @wksta + "$$"
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()
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