Recursive Direct Reports with Member, GroupCategory, GroupScope

187 views Asked by At

I may not explain this well so I will start with the results which will be an excel of Manager name, all the groups they are apart of with the category, scope and email. I was able to get the direct reports and exported all the groups they are in to an txt. I tried to use that .txt file to go through and grab each property I need from each group. That is the part I am stuck on.

 Function Get-DirectReport {
[CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true
        )][string]  $SamAccountName,
 
        [switch]  $NoRecurse
    )
 
    BEGIN {}
 
    PROCESS {
        $UserAccount = Get-ADUser $SamAccountName -Properties DirectReports, DisplayName
        $UserAccount | select -ExpandProperty DirectReports | ForEach-Object {
            $User = Get-ADUser $_ -Properties DirectReports
            if ($null -ne $User.EmployeeID) {
                if (-not $NoRecurse) {
                    Get-DirectReport $User.DirectReports
                }
                [PSCustomObject]@{
                    DirectReports     = $User.DirectReports
                                     
                }
            }
        }
    }
 
    END {}
 
}
0

There are 0 answers