Exchange 2010 PowerShell frollicks

I've been busy working on troubleshooting some Exchange 2010 issues, well not really issues with Exchange but issues within our internal processes around Exchange 2010.

One of these is how do we work with new starters and how do we process when an employee leaves?

This raises a couple of interesting changes in how Exchange 2010 "does things" our old process of dealing with leavers just disabled the AD account, people no longer got email.  This doesn't work in Exchange 2010.

I now use an email policy to change the leavers email address to something valid within Exchange however not valid outside, i.e. no MX record point to this domain name.

This then leaves all the old emails still valid and assigned to the mailbox.  So I found some nifty (I think) PowerShell to remove all the SMTP addresses from the mailbox except the primary SMTP address.

Here you go:

# Use this to remove all SMTP email addresses from a mailbox
# except for the primary
$mailbox = Get-Mailbox <mailbox id>
$all_emails = $mailbox.emailaddresses
$emails = $all_emails | Where-Object{-not $_.PrimarySMTPAddress}

if($emails){
    foreach($email in $emails){
        $mailbox | Update-List -Property emailaddresses -Remove $email | Out-Null
}

pretty simple really but might help you, if only in finding this via Google :)

Comments

Popular posts from this blog

PXE booting, MDT and 802.1x

Intune installation requires a wire...or does it?

Security Policy 1001