What determines the "rank" of a group member?
What determines the "AD management" hierarchy?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Powershell 5.1
AD module install
I would like to send out some email notifications to the highest-ranking member in an AD security group. I also want to query the AD management hierarchy and send an email notification to their managers.
Thanks,
John
What determines the "rank" of a group member?
What determines the "AD management" hierarchy?
The possible ranks are: Engineering Lead, Manager, Director, and Executive Director and they would be populated in the "job title" field in AD for the user.
The AD manager is populated in the Use's AD profile, field: Manager
I haven't run this, but see if it gives you a way to get the information you want to send the e-mail:
$Rank = @{
"Engineering Lead" = 3
Manager = 2
Director = 1
"Executive Director" = 0
}
$Ranking = @{} # will hold all the users with the job titles in $Rank and the their managers
$Group = "MyGroup" # must be usable as an "Identity"
Get-ADGroupMember -Identity $Group |
Where-Object {objectCategory -eq 'user'} | # distinguish between user and computer (both are "user" objectClass)
ForEach-Object{
$u = Get-ADUser -Identity $_.distinguishedName
if ($Rank.ContainsKey($u.Title)){ # is this user's job title one of interest?
if ($Ranking.ContainsKey($Rank.($u.Title))){ # has another user been found with the same ranking?
$h = [PSCustomObject]@{ # add whatever properties you want to the PSCustomObject
Name = $u.distinguishedName
Mgr = $u.manager
}
$Ranking.($Rank.($u.Title)) += $h # add user's DN and manager
}
else{ # first title of this rank has been found
$h = [PSCustomObject]@{ # add whatever properties you want to the PSCustomObject
Name = $u.distinguishedName
Mgr = $u.manager
}
$Ranking.($Rank.($u.Title)) = ,$h # use the "magic comma" to create an array of user/manager DNs
}
}
}
$Ranking.Keys |
Sort-Object |
Select-Object -First 1 |
$NamesAndManagers = $Ranking[$_] # a array PSCustomObject user and manager DNs for the highest ranking user(s) in the group
# Use $NamesAndManagers to get the managers e-mail address
# and send them the mail
# Be careful, becasue the highest ranking user may not have a manager!