Reputation: 327
I use this command post in an other of my questions. I'm searching how can I convert the manager field from DistinguishedName to Name (First name, last name)
Search-ADAccount -UsersOnly -AccountDisabled:$false | Get-ADUser -Properties Name, manager| select Name, manager
Upvotes: 0
Views: 6599
Reputation: 1
A cleaner version of the previous answer.
Search-ADAccount -UsersOnly -AccountDisabled:$false | Get-ADUser -Properties Name, manager| select Name, @{N='Manager';Expression={(Get-ADUser $_.Manager).name}}
Upvotes: 0
Reputation: 3784
This will do it. I'm basically extracting the text in the manager DN from the first instance of "=" to the first instance of ","
Search-ADAccount -UsersOnly -AccountDisabled:$false | Get-ADUser -Properties Name, manager| select Name, @{N='Manager';E={$_.Manager.Substring($_.Manager.IndexOf("=") + 1, $_.Manager.IndexOf(",") - $_.Manager.IndexOf("=") - 1)}}
Upvotes: 1