What Computer is Being Used to Connect to Lync?

One of my users came to me complaining that he was logging out of his computer at the end of the day, but when he would come in the next day, he would often have emails showing that others were trying to IM. He did a little digging and found out that he was showing as away, even though he was logged out of his computer.

Well, logic dictates that Lync is awesome and doesn’t screw up. Smile So, that means that he must have been logged in on another computer. The question is, how do you find what computer has his session running.

So, to help this ONE person, I spend a couple of hours and put this script together and tested it. You can just change the $UserName variable, and it will do the rest. The code is below.


# The name information below may need to be changed to include the SIP Suffix.

$UserName = “russ.kaufmann”

$FirstPriority = Get-CsUserPoolInfo $UserName | Select –ExpandProperty PrimaryPoolMachinesInPreferredOrder | Select fqdn -First 1

$ServerName = $FirstPriority.fqdn

$SQLQuery = “Select





From RegistrarEndpoint

WHERE SipHeaderFrom LIKE ‘%$UserName%'”

$connection = New-Object system.data.sqlclient.sqlconnection

$Connection.connectionString=”Data Source=$ServerName\RTCLOCAL;Initial Catalog=RTCDyn;Integrated Security=SSPI”


$Command = $Connection.CreateCommand()

$Command.Commandtext = $SqlQuery

$DataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $Command

$Dataset = New-Object System.Data.Dataset


# $Dataset.Tables[0] | Export-CSV UserIP.csv -notype


$connection = $null

$Results = $dataset.tables[0].rows

ForEach ($r in $Results){

                if ($r.IsServerSource -ne “False”){

                                  $ClientApp = $r.ClientApp

                                 $ContactInfo = $r.ContactInfo

                                $SipHeaderFrom = $r.SipHeaderFrom

                                $EncodingType = “System.Text.ASCIIEncoding”

                                $Encode = new-object $EncodingType

                                $ClientApp = $Encode.GetString($ClientApp)

                                $ContactInfo = $encode.getstring($ContactInfo)

                                $SipHeaderFrom = $encode.getstring($SipHeaderFrom)

                                # Strip garbage from $ContactInfo to get IP

                                                $CI = $ContactInfo.split(‘;’)

                                                $CI2 = $CI[0]

                                                $CI3 = $CI2.split(‘:’)

                                                $ClientIp = $CI3[1]

                                #Strip garbage from $Sip User to get SIP address in SMTP format

                                                $Sip = $SipHeaderFrom.split(‘:’)

                                                $Sip2 = $Sip[1]

                                                $Sip3 = $Sip2.split(‘>’)

                                                $SipAddress = $Sip3[0]

                                write-host $SipAddress

                                write-host $ClientIp    

                                write-host $ClientApp 



What you will get is a result something like here:



UCCAPI/15.0.4641.1000 OC/15.0.4641.1000 (Microsoft Lync)


UCCAPI/15.0.4641.1000 OC/15.0.4641.1000 (Microsoft Lync)PS D:\ece_scripts>                                     

The “2” is the number of incidents found., then the output from the script is provided in the form of the SIP address, the IP address, and the client application information.

This entry was posted in Uncategorized. Bookmark the permalink.

5 Responses to What Computer is Being Used to Connect to Lync?

  1. Pingback: Weekly IT Newsletter – September 29–October 2nd, 2014 | Just a Lync Guy

  2. Dan Bacon says:

    Great script! I’ve been looking for a way to get where users are logged in from for a long time. I’m not getting the IP info though. The ContactInfo variable only has the Sip address, no IP info. Any ideas what’s wrong?

  3. Pingback: Getting Lync User Connection Information | Build Your Business on a Solid Infrastructure

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s