Compare Primary SMTP address with SIP address

If you have an Exchange environment as well as Office Communications Server or Lync, you might have users which had their e-mail address updated but their SIP address remained the same… For a quick way to find these users, you can use the following script:


[String] $strPrimaryAddress

[String] $strSIP

[Array] $arrCollection = @()


ForEach ($mbx in (Get-Mailbox -ResultSize Unlimited))


       # Initialize object to hold all the information

       $mbcomb = "" | Select "Display Name", "Primary SMTP Address", "SIP"


       # Reset variables

       $strPrimaryAddress = $strSIP = $NULL


       # Check all the e-mail aliases the user has

       $mbx.EmailAddresses | ForEach {

              If ($_.IsPrimaryAddress -and $_.Prefix -match "SMTP") { $strPrimaryAddress = $_.SmtpAddress }

              If ($_.PrefixString -eq "sip") { $strSIP = $_.AddressString }



       # Compare the primary SMTP with the SIP address

       If ($strPrimaryAddress -ne $strSIP)


              $mbcomb."Display Name" = $mbx.DisplayName

              $mbcomb."Primary SMTP Address" = $strPrimaryAddress

              $mbcomb."SIP" = $strSIP


              $arrCollection += $mbcomb




# Print or export all the results

$arrCollection | FT

#$arrCollection | Export-Csv D:\Scripts\"SMTPvsSIP_$(Get-Date -f 'yyyyMMdd').csv" -NoType

About The Author

6 thoughts on “Compare Primary SMTP address with SIP address”

  1. No matter what I do, the output never gets fully populated. I get a csv with the headers for Display name, Primary SMTP addresss, and SIP, but the SMTP and SIP columns are blank.

    1. Hi Felix,

      Are you using the exact same code as above? Those two properties should get populated, at the least the SMTP one. Try printing them while the script runs and check what you get. For example, instead of:

      If ($_.IsPrimaryAddress -and $_.Prefix -match “SMTP”) { $strPrimaryAddress = $_.SmtpAddress }
      If ($_.PrefixString -eq “sip”) { $strSIP = $_.AddressString }


      If ($_.IsPrimaryAddress -and $_.Prefix -match “SMTP”) { $strPrimaryAddress = $_.SmtpAddress; $strPrimaryAddress}
      If ($_.PrefixString -eq “sip”) { $strSIP = $_.AddressString; $strSIP}


    1. I have used it many times before in different environments and have never had any problems… Try the suggestion I made in my previous comment to Felix.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top