locked
Powershell - Match DisplayName to PrimarySMTPAddress RRS feed

  • Question

  • Hello,

    I am trying to change the DisplayName value of all mailboxes in our organization to match the PrimarySMTPAddress. I am a bit of a novice in PowerShell but below is the syntax I've tried to use in my lab, as well as the error messages I've received. I am hoping someone can help me figure out the correct syntax? 

    Code:

    [PS] C:\Windows\system32>Get-Mailbox | foreach ($_){Set-Mailbox -DisplayName = $_.PrimarySMTPAddress}

    Error Message:

    Cannot process argument transformation on parameter 'Identity'. Cannot convert the "RNagle@contoso.local" value of type
     "Microsoft.Exchange.Data.SmtpAddress" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter".
        + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindin...mationException
        + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Mailbox

    Thanks!


    • Edited by mlpx86 Thursday, July 12, 2012 1:54 PM Changed Command to PrimarySMTPAddress instead of WindowsEmailAddress
    Thursday, July 12, 2012 1:53 PM

Answers

  • Hi

    I can't get this to work as a one-liner (not sure why and don't have a gap to find out right now) but it's an easy two-liner:

    $mb = Get-Mailbox
    foreach ($n in $mb) {Set-Mailbox $n.name -DisplayName $n.primarysmtpaddress}

    Cheers, Steve

    • Marked as answer by mlpx86 Thursday, July 12, 2012 2:34 PM
    Thursday, July 12, 2012 2:12 PM

All replies

  • Hi

    I can't get this to work as a one-liner (not sure why and don't have a gap to find out right now) but it's an easy two-liner:

    $mb = Get-Mailbox
    foreach ($n in $mb) {Set-Mailbox $n.name -DisplayName $n.primarysmtpaddress}

    Cheers, Steve

    • Marked as answer by mlpx86 Thursday, July 12, 2012 2:34 PM
    Thursday, July 12, 2012 2:12 PM
  • Works for me. Thanks!
    • Proposed as answer by Divya Admin Thursday, January 8, 2015 11:56 AM
    Thursday, July 12, 2012 2:34 PM