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

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 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.

 

Leave a Comment
  • Please add 1 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 4. Comment: Replaced RGB values with color names in HTML to restore colors

  • Richard Mueller edited Revision 3. Comment: Removed (en-US) from title

  • Craig Lussier edited Revision 2. Comment: added en-us to tags and title

Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Craig Lussier edited Revision 2. Comment: added en-us to tags and title

  • Richard Mueller edited Revision 3. Comment: Removed (en-US) from title

  • Richard Mueller edited Revision 4. Comment: Replaced RGB values with color names in HTML to restore colors

Page 1 of 1 (3 items)