|
|
|
| 17 June 2002 | InContainer() |
| Author | Howard A. Bullock |
| Action | Determines if the current NT4 acount name type of the user or computer is a member of a specific container (OU, Computers, etc) in Active Directory. |
| Syntax | InContainer ($Container, $NameType) |
| Parameters | |
| Remarks | This function requires the UDF TranslateName() and determines if the specified object is in the specified container or a child container. OU's are not like groups. Group names must be unique. OU's on the other hand do not have to be unique. Therefore, one can not simply parse the DN and match a single OU name and be sure that the match OU is indeed the exact OU specifed. |
| 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 UDFs: 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 1 ? "Error"
endselect
|
| Source |
FUNCTION InContainer ($container, $nametype)
DIM $container, $currentcontainer, $nametype, $name1, $name2
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
$currentcontainer = Substr($name2[0], InStr($name2[0], ",")+1)
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 ; - InContainer -
|
|
|
|