Direct reports

Skip Hofmann 186 Reputation points
2021-12-11T13:12:25.8+00:00

Hello

I need help putting together a script that will look at one user (Bossman). Get Bossman's direct reports, and Bossman's indirect reports, (recursive) . I need to skip if the account name contains below, and skip if DNS contains below. Then populate these users into "GroupA". I came up with the below script, but i am struggling to put this all together. Any help is greatly appreciated

-and ($_.distinguishedName -notcontains 'Disabled Users - Email Hold') -and ($_.distinguishedName -notcontains 'Svc Accnts')
-and ($
.name -notcontains 'admin') -and ($_.name -notcontains 'test')
-and ($.name -notcontains 'Ford') `
-and ($
.name -notcontains 'Mustang')

function Get-Reports ([string] $manager) {
  $users = Get-ADUser -Filter "manager -eq '$manager'"
  if ($users -ne $null){
    $users
  }
  $users | % { Get-Reports $_ }
}

# Usage
(Get-Reports Bossman)
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2021-12-11T19:24:46.623+00:00

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.