scripting@wanadoo.nl




InContainer()

http://www.scriptlogic.com/kixtart/FunctionLibrary_FunctionList.aspx


actual FunctionLibrary list on 'Scriptlogic' site printer-friendly mirror of UDF topic on 'scripting@wanadoo.nl' site close
17 June 2002 InContainer()
AuthorHoward 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.
SyntaxInContainer ($Container, $NameType) 
Parameters
  • $Container (Required / String) Dinstinghished name of the container to check. This must be the fully qualified DN to accurately make a determination.
  • $NameType (Required / String) "User" or "Computer" 
  • RemarksThis 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. 
    ReturnsAn 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 
    DependenciesOS: 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 -
     
      original source of UDF topic. show actual FunctionLibrary list on Scriptlogic site close top
              printer-friendly mirror of UDF topic on scripting@wanadoo.nl site  




    Copyright © 2003 www.scriptlogic.com & scripting@wanadoo.nl - last updated on 20 May 2003


    Site Meter