Apr 24

Find SIP Addresses with Illegal Characters

SIP HappensOne of my peers had a Lync 2013 pool-failover scenario. Just about everything worked right except that apparently the Lync Backup Service had been getting hung up and not completing its replication cycles. They opened a case with Microsoft and one of the issues discovered was that Lync Backup Service was hanging on users whose SIP Address had illegal characters. Once they manually fixed these SIP Addresses, the Backup Service was able to complete successfully.

So what characters are illegal in a SIP address (at least so far as Lync is concerned)?

~ | { } [ ] < > ` # ^ & @

We can convert that to a Regular Expression:


Once that is done, a quick and dirty script can be written to compare every user against this Regular Expression. If the Regular Expression matches the SIP Address, then we can be notified of this.

# These are the invalid characters ~|{}[]<>`#^&@

$AddressToTest = get-csuser
$regex = "^([^~|{}[]<>#^’&@\]+)$"

Foreach ($user in $AddressToTest)

If (($User.sipaddress -split "@")[0].substring(4) -notmatch $regex)

Write-Host "Invalid username specified." $User.sipaddress

The only fancy part of this script is in the If statement. We can’t compare the entire SIP Address against the regex because the “@” will always be a match. So the Split is used to grab the left hand side of the SIP Address which is the portion that will (most likely) have illegal characters. You’ll also note the “substring” portion in the if statement. This means begin the comparison 4 characters in; skip the “sip:” portion of the returned SIP Address.

Note that if you want to test out this script in a lab environment, you can force a user to have any illegal character if you edit their SIP Address via ADSIEdit. Also note that set-csuser will permit you to edit a SIP Address and inserting a few of the above characters.

Here is sample output from the script:



Tom Arbuthnot points to a Technet document specifically calling out the unsupported usageof the hyphen and apostrophe here: http://tomtalks.uk/2014/08/apostrophe-and-dash-not-supported-in-user-sip-addresses-in-lync-server-find-problem-sip-uris/


2 pings

Skip to comment form

  1. flinchböt

    Here’s a one-liner that does the same as above:

    Get-CsUser -resultsize unlimited | where {$_.SIPAddress -match “[41-54|57|73-77|133-136|140|173-177]”} | Select-Object DisplayName, SipAddress

    1. soder

      This one gives me plenty of syntax error:

      parsing “[41-54|57|73-77|133-136|140|173-177]” – [x-y] range in reverse order.

      1. soder

        Oh, and the original script gives meaningless (incorrect) output: showing people who have proper SIP address (not illegal ones).

        1. flinchbot

          I haven’t looked at this in ages but it was pretty spot on when running in a > 100,000 user organization. I no longer have access to there so I can only test it in my 100 person lab which won’t turn up any false positives.

          1. soder

            It lists all my users (LAB system, only a handful of SIP accounts hosted) as invalid:

            Invalid username specified. sip:Lynctest01APAC@ABC.org
            Invalid username specified. sip:Lynctest01EMEA@ABC.org
            Invalid username specified. sip:Lynctest02APAC@ABC.org
            Invalid username specified. sip:Lynctest02EMEA@ABC.org
            Invalid username specified. sip:Lynctest03APAC@ABCqa.com
            Invalid username specified. sip:Lynctest03EMEA@ABCqa.com
            Invalid username specified. sip:Lynctest04APAC@ABC-ods.com
            Invalid username specified. sip:Lynctest04EMEA@ABC-ods.com
            Invalid username specified. sip:stephen.tyyyy@ABC.org
            Invalid username specified. sip:svc_dma-apac-sfb@ABC.org
            Invalid username specified. sip:svc_dma-emea-sfb@ABC.org
            Invalid username specified. sip:test.lcs2@ABC.org
            Invalid username specified. sip:test.lcs3@ABC.org

  2. soder

    Ok, I dont some tests, and the “same” sourcecode copy-pasted from Tom Arbuthnots blogpost indeed works, and doesnt return anything back (I didnt test it wioth faulty SIPaddress). I compared the source from here and from Toms article, and the only difference I could spot is the doublequote character. So it must be something with those bloody ” s…

  3. soder

    Hm,, I found it: you have incorrectly encoded the [ and the ] in the regexp:

    $regex = “^([^~|{}[]#^’&@\]+)$”

    versus Toms:

    $regex = “^([^~|{}\[\]#^’&@\\]+)$”

  1. NeWay Technologies – Weekly Newsletter #92 – April 25, 2014 | NeWay

    […] Find SIP Addresses with Illegal Characters – […]

  2. Apostrophe and dash not supported in user SIP addresses in Lync Server – Find Problem SIP URIs | Tom Talks UC

    […] great post from thoughts from a bot named flinch (great blog, you should follow it), pointed out some time ago the challenges with unusual/illegal […]

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

%d bloggers like this: