Forum Discussion
Export AD manager name
- Mar 19, 2024
shadowwebs I changed the script a bit for you 🙂
$total = foreach ($member in Get-ADGroupMember -Identity 'UK-Admin-Users') { $user = Get-ADUser -Identity $member -Properties Name, Enabled, samAccountName, CanonicalName, Manager [pscustomobject]@{ Name = $user.Name Enabled = $user.Enabled SamAccountName = $user.SamAccountName Canonicalname = $user.DistinguishedName Manager = if ($null -ne $user.Manager) { $((Get-ADUser -Identity $user.Manager -Properties Displayname).DisplayName) } else { "No Manager specified" } } } $total | Export-CSV C:\Temp\PS\Output\Usersdetail.csv -NoTypeInformation -Delimiter ';' -Encoding UTF8
If specified in the user account, this will output the manager field as the DisplayName. I also used Get-ADGroupMember to retrieve the members of the group.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If one of the posts was helpful in other ways, please consider giving it a Like.
shadowwebs I changed the script a bit for you 🙂
$total = foreach ($member in Get-ADGroupMember -Identity 'UK-Admin-Users') {
$user = Get-ADUser -Identity $member -Properties Name, Enabled, samAccountName, CanonicalName, Manager
[pscustomobject]@{
Name = $user.Name
Enabled = $user.Enabled
SamAccountName = $user.SamAccountName
Canonicalname = $user.DistinguishedName
Manager = if ($null -ne $user.Manager) { $((Get-ADUser -Identity $user.Manager -Properties Displayname).DisplayName) } else { "No Manager specified" }
}
}
$total | Export-CSV C:\Temp\PS\Output\Usersdetail.csv -NoTypeInformation -Delimiter ';' -Encoding UTF8
If specified in the user account, this will output the manager field as the DisplayName. I also used Get-ADGroupMember to retrieve the members of the group.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If one of the posts was helpful in other ways, please consider giving it a Like.