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

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.

Like what you read? Give Matt Ellis a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.