Exchange powershell Script

Welcome Forums General PowerShell Q&A Exchange powershell Script

This topic contains 4 replies, has 4 voices, and was last updated by

2 years ago.

  • Author
  • #64528

    Points: 0
    Rank: Member


    I can't remove SMTP address from Exchange server via a script.
    I want to change primary SMTP address and remove the old one. to
    I can add and change primary SMTP address but I can't remove old one. If anyone emails it should bounce.

    Set-Mailbox $mbox -PrimarySmtpAddress $NewSMTP -EmailAddressPolicyEnabled $false

    This does not work:
    Set-Mailbox $mbox -EmailAddresses @{Remove=$OldSMTP}

    It works if i run it in exchange management console.

    Any ideas?

  • #64564

    Points: 694
    Helping Hand
    Rank: Major Contributor

    Why shouldn't it work in a script? Do you get errors? If yes – show it.

  • #64567

    Points: 2
    Rank: Member

    What error are you getting? If I read it right, the first command is changing the primary address, so the old one doesn't need to be removed.

  • #64597

    Points: 1
    Rank: Member

    In Exchange, the proxyAddresses(the AD attribute that is presented by the EmailAddresses) are meant to keep track of the addresses associated to a user in order to maintain consistency in delivery (so if I know you were working at, and it get acquired by, causing your primary smtp address to switch to the latter, then I can still pretend to reply to old email you sent me where was the source address).

    Said so, the EmailAddresses filed is returned as an array, and you can't subtract from an Array object.
    something like this should work:
    $mbx = Get-Mailbox
    $addresses = $mbx.EmailAddresses | where{$_ -ne ""}
    #Set-Mailbox -EmailAddresses $addresses

    Just uncomment the last Set- if the content of $addresses is what you expect it to be

  • #64614

    Points: 0
    Rank: Member

    Yes I get errors when running Set-Mailbox $mbox -EmailAddresses @{Remove=$OldSMTP} via a script connecting to Exchange powershell, but not if I run it in Exchange PS console. I'll have to get back with errorcode.
    Everything else works, everyone gets a new primary SMTP address. It's just the old one that needs to be removed, the decision has been made.

    I think you're on to something fpoli 🙂

    That will most likly do what I want. I'll test it soon.
    As it is now, $mbx.EmailAddresses will contain, SIP, SMTP, x400 addresses that I don't want removed.
    The old SMTP addresses just needs to be removed,
    And I really don't want to change 150+ addresses by hand.

    I really appreciate every answer. It's amazing, thank you all.

The topic ‘Exchange powershell Script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort