UserPrincipalName (UPN), Email Address & SIP Address Mismatch Report

Matt Ellis
Jul 27, 2018 · 2 min read

I decided to try and have a little cleanup recently and was shocked by the number of accounts we had that over time had ended up with mismatching UserPrincipalName (UPN), email address (PrimarySMTPAddress) or SIP address values.

I started off with the following one liners to show me the offending accounts but ended up writing something (very) simple but a little more complete that I could use in Excel and keep running in the future to keep on top of it.

All these commands use Get-CsAdUser so you either need to be on a Lync or Skype server or have the tools installed to be able run this. The commands exclude any users that don’t have a UPN, email address or SIP Address assigned.

Mismatching UserPrincipalName (UPN) & Email Address

Get-CsAdUser -ResultSize Unlimited | ? {($_.UserPrincipalName -and $_.WindowsEmailAddress) -and ($_.UserPrincipalName.ToLower() -ne $_.WindowsEmailAddress.ToLower())} | ft SamAccountName, DisplayName, UserPrincipalName, WindowsEmailAddress -AutoSize

Mismatching UserPrincipalName (UPN) & SIP Address

Get-CsAdUser -ResultSize Unlimited | ? {($_.UserPrincipalName -and $_.SipAddress) -and ($_.UserPrincipalName.ToLower() -ne $_.SipAddress.ToLower().Replace("sip:",""))} | ft SamAccountName, DisplayName, UserPrincipalName, SipAddress -AutoSize

Mismatching Email Address & SIP Address

Get-CsAdUser -ResultSize Unlimited | ? {($_.WindowsEmailAddress -and $_.SipAddress) -and ($_.WindowsEmailAddress.ToLower() -ne $_.SipAddress.ToLower().Replace("sip:",""))} | ft SamAccountName, DisplayName, WindowsEmailAddress, SipAddress -AutoSize

Overall Report

This report basically brings together all three commands above and gives you a couple of CSV files at the end. One has all the output and one just has all the ‘issues‘ which is basically where something doesn’t match on a particular user’s account.

As a guide, in my environment it found and compared 22,000 objects in about 140 seconds. So, that’s not too bad. Just paste the code below into something like ISE and run it. You might want to play with the Export-Csv output location at the bottom if you want to control where the reports end up.


Matt Ellis

Written by

Unified Communications Architect, Pompey fan, burger eater, coffee drinker...

365 UC

365 UC

Stories from the world of UC by a bunch of UC professionals…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade