Find the top-level manager for any Active Directory user

I was recently asked to report on who the vice president is for a list of users. The PowerShell function below does that for the users who have a manager designated on their Active Directory account. It excludes the President and Provost, so essentially reports to the level just below their positions.

function Get-TopLevel
param ($userID)
$subject = Get-ADUser $userID -Properties manager, displayName

if ($subject.manager -eq $null) {
Write-Host “No manager data available.”
else {
$userObj = $subject
while `
(($userObj.manager -ne $null) -and `
($userObj.manager -ne ‘CN=President,OU=Employee,OU=People,DC=university,DC=edu’) -and `
($userObj.manager -ne ‘CN=Provost,OU=Employee,OU=People,DC=university,DC=edu’))
$userObj = Get-ADUser $userObj.manager -Properties manager, displayName
# $userObj.displayName
Write-Host $userObj.displayName

By Tommy Doan


Leave a Reply

Your email address will not be published. Required fields are marked *