SOLVED

Export AD manager name

Copper Contributor

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 which works perfectly at the moment, but i'm looking to take this a step further, which is that instead of displaying the Manager along with the OU detail, i'd like this to display only the Manager display name, whilst also exporting the other information as in the script as required.

Any help would be greatly appreciated.


Get-ADGroup "UK-Admin-Users" -Properties Member | Select-Object -ExpandProperty Member | Get-ADUser -Properties * | select name, enabled, samAccountName, CanonicalName, manager | Export-CSV C:\Temp\PS\Output\Usersdetail.csv

1 Reply
best response confirmed by shadowwebs (Copper Contributor)
Solution

@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.

1 best response

Accepted Solutions
best response confirmed by shadowwebs (Copper Contributor)
Solution

@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.

View solution in original post