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:

Invalid_URI_Capture

 

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/

10 comments

2 pings

Skip to comment form

  1. 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

      • soder on 2017/02/14 at 09:40
      • Reply

      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.

        • soder on 2017/02/14 at 09:44
        • Reply

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

        1. 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.

            • soder on 2017/02/14 at 12:20

            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

    • soder on 2017/02/14 at 12:32
    • Reply

    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…

    • soder on 2017/02/14 at 12:35
    • Reply

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

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

    versus Toms:

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

    • soder on 2017/09/14 at 03:43
    • Reply

    You are not really spending time on your blog since you joined the dark side… 🙁 Always sad to see talents lost….

    1. Oh I’m about to launch an epic 6 part series on my MS Blog. It might not be until October or November, but work is being done in the background.

    • Tejas Haria on 2019/11/01 at 06:34
    • Reply

    I copied and ran the whole script as it is. I do see SIP URIs which does not have any restricted characters. Am I doing anything wrong?

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

  2. […] 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 to Apostrophe and dash not supported in user SIP addresses in Lync Server – Find Problem SIP URIs | Tom Talks UC Cancel reply

Your email address will not be published.