lotirthos227
lotirthos227

Reputation: 327

Powershell - Convert DistinguishedName to Name in a Piped Command

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

Answers (2)

Claudio Tarabocchia
Claudio Tarabocchia

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

Musaab Al-Okaidi
Musaab Al-Okaidi

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

Related Questions