Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Update Lync Client (2013) Location Field with GeoIP Location Data
#requires Version 3.0
Updates Lync 2013 Client's location information with geolocation data based on internet ip address.
The Update-LyncLocation.ps1 script updates the Lync 2013 Client's location information. It uses the
Telize web service to determine your external ip address and then queries Telize to collect publicly
available geolocation information to determine your location. That data is then parsed into usable
information and published to the Lync client.
****Requires Lync 2013 SDK.**** The SDK install requires Visual Studio 2010 SP1. To avoid installing
Visual Studio, download the SDK, use 7-zip to extract the files from the install, and install the MSI
relevant to your Lync Client build (x86/x64).
None. You cannot pipe objects to Update-LyncLocation.ps1.
None. Update-LyncLocation.ps1 does not generate any output.
Author Name: Andrew Healey (@healeyio)
Creation Date: 2015-01-04
Version Date: 2015-01-26
Lync 2013 SDK:
IP Geolocation Web Service:
PS C:\PS> .\Update-LyncLocation.ps1
# Verify lync 2013 object model dll is either in script directory or SDK is installed
$lyncSDKPath = "Microsoft Office\Office15\LyncSDK\Assemblies\Desktop\Microsoft.Lync.Model.dll"
$lyncSDKError = "Lync 2013 SDK is required. Download here and install:"
if (-not (Get-Module -Name Microsoft.Lync.Model)) {
if (Test-Path (Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath $lyncSDKPath)) {
$lyncPath = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath $lyncSDKPath
elseif (Test-Path (Join-Path -Path ${env:ProgramFiles} -ChildPath $lyncSDKPath)) {
$lyncPath = Join-Path -Path ${env:ProgramFiles} -ChildPath $lyncSDKPath
else {
$fileError = New-Object"SDK Not Found: $lyncSDKError")
throw $fileError
} # End SDK/DLL check
try {
Import-Module -Name $lyncPath -ErrorAction Stop
catch {
$fileError = New-Object ("Import-Module Error: $lyncSDKError")
throw $fileError
} # End object model import
} # End dll check
# Check if Lync is signed in, otherwise, nothing to do
$Client = [Microsoft.Lync.Model.LyncClient]::GetClient()
if ($Client.State -eq "SignedIn") {
# Get external ip address
$WanIP = (Invoke-WebRequest -Uri "" -UseBasicParsing).Content
# Get geolocation data
$data = Invoke-WebRequest -Uri "$WanIP" -UseBasicParsing | ConvertFrom-Json
### Format the location from returned geolocation ###
### More Info Here: ###
# Deal with oddities like anonymous proxies
if (($data.continent_code -eq "--") -or ($data.continent_code -eq $null)) {$location = "$($data.isp)"}
# If the city and state are not null, make it City, State
elseif (($data.region_code -ne $null) -and ($ -ne $null)) {$location = "$($, $($data.region_code)"}
# If the city is null but state/region has a value, make it Region, Country
elseif (($data.region -ne $null) -and ($ -eq $null)) {$location = "$($data.region), $($data.country_code3)"}
# Else, just output the Country
else {$location = "$($"}
# Update location in Lync
$LyncInfo = New-Object 'System.Collections.Generic.Dictionary[Microsoft.Lync.Model.PublishableContactInformationType, object]'
$LyncInfo.Add([Microsoft.Lync.Model.PublishableContactInformationType]::LocationName, $location)
$Self = $Client.Self
$Publish = $Self.BeginPublishContactInformation($LyncInfo, $null, $null)
else {
Write-Warning "Lync must be signed in."
} # End client sign-in check

This comment has been minimized.

Copy link

commented Oct 16, 2017

The Telize free API has been killed, but you could use which is free for up to 1k req/day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.