Forum Discussion

shadowwebs's avatar
shadowwebs
Copper Contributor
Mar 18, 2024
Solved

Export AD manager name

Hi all, I'm not advanced with PowerShell and won't admit to being, but wondered if someone may be able to help me with this one ?  This is to work with AD on-prem, not AAD I've got the below script...
  • Harm_Veenstra's avatar
    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.

Resources