public/Get-RBACOrg.ps1

function Get-RBACOrg {
    Param
    (
        # Name of Org to get details on
        [Parameter(ParameterSetName="None",ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [Parameter(ParameterSetName="Mock",Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [ArgumentCompleter( {
            param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters )
            (get-rbacOrg -org "$wordToComplete*").Org
        })]
        [String]$Org,

        # Normally only org, description, and DN are included. This provides unfiltered output and matches get-rbacComponent's detailed format
        [switch]$Detailed,

        # Don't search AD-- mock what you would get.
        [Parameter(ParameterSetName="Mock",Mandatory)]
        [switch]$Mock,

        [Parameter(ParameterSetName="Mock",ValueFromPipelineByPropertyName, ValueFromPipeline)]
        [String]$Description="Mock Description",

        [Microsoft.ActiveDirectory.Management.ADDirectoryServer]$Server = (get-addomainController -Writable -Discover)

    )

    Begin {
        $SearchParams = @{
            SearchScope = "OneLevel"
            Properties = "Description"
        }
        $SearchBase = @{ SearchBase =  $Settings['OUPaths']['OrgsBase'] }
    }

    PROCESS {
        if ($org)
        {
            $filter = @{ filter = "name -like '$org'" }
        } Else {
            $filter = @{ filter = "*" }
        }

        $OUList = $(
            if ([bool]$mock) {
                @{
                    Name = $Org
                    Description = $Description
                    DistinguishedName = "OU={0},{1}" -f $org, $settings['OUPaths']['OrgsBase']
                }
            } else {
                get-adorganizationalUnit @SearchBase @SearchParams @Filter | foreach-object {
                    @{
                        Name = $_.name
                        DistinguishedName = $_.distinguishedName
                        Description = $_.description
                    }
                }
            }
        ) | foreach-object {
            $BaseDN = $_.distinguishedName
            $Children = $(
                if ([bool]$mock) {
                    $OrgTemplate['LDAPContainers']
                } else {
                    get-adorganizationalUnit -searchBase $BaseDN @SearchParams -filter "*" | foreach-object {
                        @{
                            DistinguishedName = $_.distinguishedName
                            Description = $_.description
                        }
                    }
                }
            ) | foreach-object {
                [pscustomobject]$_
            } | resolve-rbacchildren -baseDN $baseDN

            [PSCustomObject]@{
                Name = $_.name
                Type = "Org"
                Org = $_.name
                Component = ""
                Description = $_.Description
                DistinguishedName = $BaseDN
                Path = split-ldappath -DistinguishedName $BaseDN -Parent
                ObjectMidName = "{0}" -f $_.name
                Parent = $Settings.names.GlobalOU
            }
            if ($_.name -ne $settings.names.GlobalOU) {
                $ThisOrg
            } elseif ([Bool]$IncludeGlobal) {
                $thisOrg.Type = "Global"
                $ThisOrg
            } else {
                Write-Verbose "Skipping global Org, IncludeGlobal not specified"
            }
        }
        if (-not [bool]$Detailed) {
            $OUList | select-object Org,Description,DistinguishedName
        } else {
            $OUList
        }

    }
}