Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have bunch of users which DisplayNames I changed mistakenly to some string (for example: xyz)

But there is one field called Name which has FirstName and Lastname. What I want is take all users who has xyz in it and them change DisplayName to the corresponding Name.

Get-Mailbox -ResultSize Unlimited -Filter {DisplayName -like "*xyz*"} |

This gives me the array I need whose DisplayNames i need to change. What I add after the "pipe" ?

I googled a lot, however couldn't come up with the answer.

I tried:

Set-Mailbox -DisplayName $_.Name

However it says

Cannot bind parameter 'DisplayName' to the target. .... cannot be null/empty.

How can I set DisplayName to the same value as Name?

share|improve this question

There's no $_ variable when piping from one cmdlet to the next directly. So Set-Mailbox is seeing a $null for the DisplayName parameter and failing. Try wrapping the Set-Mailbox command in a ForEach-Object call (alias %) to get that $_ variable, like so:

Get-Mailbox -ResultSize Unlimited -Filter {DisplayName -like "*xyz*"} | % {Set-Mailbox  -Identity $_.PrimarySmtpAddress -DisplayName $_.Name}
share|improve this answer
I did the following: Get-Mailbox -ResultSize Unlimited -Filter {DisplayName -like "*Firstname Lastname*"} | % {Set-Mailbox -DisplayName $_.Name} however – epema Mar 15 '13 at 3:31
it says Pipeline not executed because a pipeline is already executin – epema Mar 15 '13 at 3:41
Sorry, you DO need "-Identity $_.PrimarySmtpAddress" in the Set-Mailbox call. I will edit the answer to reflect the full command. – jbsmith Mar 15 '13 at 16:46
up vote 0 down vote accepted

Here is the solution:

$mbxs = Get-Mailbox -ResultSize Unlimited -Filter {DisplayName -like "*FirstName Lastname*"}
$mbxs | foreach { %{Set-Mailbox -Identity $_.PrimarySmtpAddress -DisplayName $_.Name}}

Thanks all!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.