public/Get-RBACComponent.ps1

Function get-RBACComponent {
    [CmdletBinding(DefaultParameterSetName='None')]
    Param
    (
        [Parameter(Mandatory=$False, Position = 0, ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true)]
        [Parameter(ParameterSetName = 'SpecificComponent', Mandatory=$True, ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true)]
        [ValidateScript({ [bool](get-rbacOrg -org $_) })]
        [ArgumentCompleter( {(get-rbacOrg).Org})]
        [String[]]$Org,
        
        [Parameter(ParameterSetName = 'SpecificComponent', Mandatory=$False, Position = 1, ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true)]
        [ArgumentCompleter( {(get-rbacComponent).Component})]
        [String[]]$Component,

        [switch]$Detailed
    )

    BEGIN {
      # $OrgPath = "OU=$($OrgsOUStruct.Name),$($OrgsOUStruct.Path)"
    }

    PROCESS {
        if ($PsItem.org) {
            $Org = $_.Org
        } elseif ($PsItem) {
            $Org = $_
        }
        if ($org) {
            $OrgList = get-rbacOrg -org $Org
        } else {
            $OrgList = Get-RBACOrg
        }

        if ($Component) {
            $filter = "name -eq '$Component'"
        } Else {
            $filter = "*"
        }
      
        ForEach ($Item in $OrgList) {
            $SearchBase = "OU={0},{1}" -f $ComponentsOUStruct.Name, $Item.distinguishedName
            $OrgName = $item.org
            $SearchParams = @{
                SearchBase = $SearchBase
                SearchScope = "OneLevel"
                Filter = $filter
            }
           $OUList = get-adorganizationalUnit @SearchParams -properties description | foreach-object {
                $thisComponent = [PSCustomObject]@{
                    Name = $_.name
                    Type = "Component"
                    Org = $orgName
                    Component = $_.name
                    Description = $_.Description
                    DistinguishedName = $_.distinguishedName
                    ObjectMidName = "{0}-{1}" -f $orgName,$_.name
                }
                $thisComponent
            }
            if (-not [bool]$Detailed) {
                $OUList | select-object Component,Org,Description,DistinguishedName
            } else {
                $OUList
            }
        }
    }
}