Get-DirectReports.ps1


Description

Purpose

A brief description of the Get-DirectReports function.

Detailed Description

A detailed description of the Get-DirectReports function.

Back to Top

Usage

Example 1

PS C:\> Get-DirectReports -EmployeeID 'Value1'

Back to Top

Notes

Additional information about the function.

Back to Top


Script

function Get-DirectReports {

	<#
	.SYNOPSIS
		A brief description of the Get-DirectReports function.
	
	.DESCRIPTION
		A detailed description of the Get-DirectReports function.
	
	.PARAMETER Identity
		The SamAccountName of the Manager.
	
	.EXAMPLE
		PS C:\> Get-DirectReports -EmployeeID 'Value1'
	
	.OUTPUTS
		string
	
	.NOTES
		Additional information about the function.
	#>
	
	[OutputType([string], ParameterSetName = 'Default')]
	param
	(
		[Parameter(ParameterSetName = 'Default',
			Mandatory = $true,
			ValueFromPipeline = $true,
			ValueFromPipelineByPropertyName = $true,
			Position = 0,
			HelpMessage = 'Enter the SamAccountName for the Manager whose direct reports you would like to view.')]
		[ValidateNotNullOrEmpty()]
		[string]$Identity
	)
	
	Function Get-Reports {
		[cmdletbinding()]
		Param (
			[Parameter(Position = 0, ValueFromPipelineByPropertyName = $True)]
			[string]$DistinguishedName,
			[int]$Tab = 2
		)
		
		Process {
			$direct = Get-ADUser -Identity $DistinguishedName -Properties DirectReports
			
			if ($direct.DirectReports) {
				$direct.DirectReports | Get-ADUser -Properties Title | ForEach-Object {
					"{0} [{1}]" -f $_.Name.padleft($_.name.length + $tab), $_.title
					$_ | Get-Reports -Tab $($tab + 2)
				}
			}
			
		} #process
		
	} #end function
	
	$user = Get-ADUser $Identity -Properties DirectReports, Title
	$reports = $user.DirectReports
	
	"{0} [{1}]" -f $User.name, $User.Title
	
	foreach ($report in $reports) {
		$direct = $report | Get-ADUser -Properties DirectReports, Title, Department
		"{0} [{1}]" -f $direct.name.padleft($direct.name.length + 1, ">"), $direct.Title
		$direct | Get-Reports
	} #foreach
}

Back to Top

Download

Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top