Share via


How to Use Powershell to List Names of the People who Directly and/or Indirectly Report to a Manager

FIM ScriptBox Item

Summary

This Powershell Script writes the names of the people that directly and/or indirectly report to a manager to the console.
To use this script just type the manager's name as parameter.

Script Code

 

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
set-variable -name URI -value "http://localhost:5725/resourcemanagementservice' " -option constant 
clear

If($args.count -ne 1) {Throw "Type the Manager´s Name!"}
$ManagerName = $args[0]
$Filter = "/Person[DisplayName='$ManagerName']"

If(@(Get-PSSnapin | Where-Object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {Add-PSSnapin FIMAutomation}

$curObject = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($Filter) -ErrorVariable Err -ErrorAction SilentlyContinue 
If($Err){Throw $Err}

If($curObject -eq $null) {Throw "Name not found!"} 
$attrObjectID = (($curObject.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "ObjectID"}).Value).split(":")[2]
$Filter_Manager = "/Person[Manager = '$attrObjectID']"
[array]$curObject_Direct = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($Filter_Manager) -ErrorVariable Err -ErrorAction SilentlyContinue 
write-host "This people Direct Reports to $ManagerName"
$arrayIndireto = @()
foreach($DirectReport in $curObject_Direct) 
{
 write-host " +" ($DirectReport.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "DisplayName"}).Value
 $Direct = (($DirectReport.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "ObjectID"}).Value).split(":")[2]
 $Filter_Direct = "/Person[Manager = '$Direct']"
 [array]$curObject_Indirect = export-fimconfig -uri $URI –onlyBaseResources -customconfig ($Filter_Direct) -ErrorVariable Err -ErrorAction SilentlyContinue
 foreach($InDirectReport in $curObject_Indirect) 
 {
 $Indireto = ($InDirectReport.ResourceManagementObject.ResourceManagementAttributes | Where-Object {$_.AttributeName -eq "DisplayName"}).Value
 if($Indireto.Length -gt 1)
 {
  $arrayIndireto += $Indireto
 }
 }
}

write-host ""
write-host "This people Indirect Reports to $ManagerName"
foreach($IndirectReport in $arrayIndireto)
{
 write-host " --" $IndirectReport
}
write-host ""
write-host ""
Trap 

 Throw $_.Exception.Message 
 Exit 1
}

 

Note

To provide feedback about this script, create a post on the FIM TechNet Forum.
For more FIM related Windows PowerShell scripts, see the FIM ScriptBox.

 


See Also