Thursday, December 11, 2014

Some Useful PowerShell One Liners for Lync

Useful PowerShell One-Liners for Lync

Below are some one-liners I use often in administering Lync systems, so I thought I would share this as a reference. These should be run from a Lync PowerShell Instance, unless otherwise indicated:

List a User's Response Group Memberships
get-csrgsagentgroup | Where-Object {$_.AgentsByUri -like "sip:first.last@domain.com"} | Select name

Get users in specific OU and output to csv (run from Exchange Powershell)
get-mailbox -OrganizationalUnit "ou=YourOU,dc=DOMAIN,dc=COM" -resultsize unlimited | select-object DisplayName,SamAccountName,PrimarySmtpAddress | Export-CSV e:\files\DomainUsers.csv

Invoking CMS Replication
Invoke-CSManagementStoreReplication

Getting CMS Replication Status of only Lync Servers
Get-CsManagementStoreReplicationStatus | Where-Object {$_.ReplicaFqdn -match "ServerNamingConvention" -Or $_.ReplicaFqdn -match "SBANamingConvention"} | Select ReplicaFqdn, UpToDate

Get users where External Access is…
get-csuser | Where {$_.ExternalAccessPolicy -like "PolicyName"}

Counting users who have a telephone number set in Lync
get-csuser | Sort-Object LineURI | where {$_.LineURI -ne ""} | Measure-Object

Finding AD Disabled Accounts Who are Still Lync Enabled
Get-CsAdUser | ?{$_.UserAccountControl -match "AccountDisabled" -and $_.Enabled -eq $true} | ft Name,Enabled,SipAddress -auto

Counting AD Disabled Accounts Who are Still Lync Enabled
Get-CsAdUser | ?{$_.UserAccountControl -match "AccountDisabled" -and $_.Enabled -eq $true} | Measure-Object

List all users in a pool
get-csuser | where-object {$_.RegistrarPool -like "lyncpoolfqdn"}  | Select-Object DisplayName, LineUri

List all Common Area Phones in a pool
get-cscommonareaphone | where-object {$_.RegistrarPool -like "lyncpoolfqdn"}  | Select-Object DisplayName, LineUri

List all Analog Devices in a pool
get-csanalogdevice | where-object {$_.RegistrarPool -like "lyncpoolfqdn"} | Select-Object DisplayName, LineUri

Count How Many Users are on Lync
(Get-CsUser -OnLyncServer).Count

Get PowerShell Version (run from any PowerShell Session)
$PSVersionTable.PSVersion.Major
Or
Get-Host | Select-Object Version

Getting Relative Dates (run from any PowerShell Session)
Here's a quick and fast way of generating relative dates in any format:
(Get-Date).AddDays(-1).ToString('yyyy-MM-dd')<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office"/>

This returns all error events from the System event log in the past 48 hours: (run from any PowerShell Session)

Get-EventLog -LogName System -EntryType Error -After (Get-Date).AddDays(-2)

I'll add more as need arises. Hope these are helpful.

Monday, October 20, 2014

Exporting and Importing Lync Contacts for a User

Exporting Contacts:

To make your user's experience more seamless when moving pools or if, for some reason the user's account has to be deleted and re-created, the following procedure will allow you to export his/her contacts and then import them into the new account.

In Lync 2010:

To export a user’s contact list, we’re going to use a Lync utility called “dbimpexp.exe”. This utility is included in the Resource Kit, so obviously, that must be installed before you can access the utility. Open a command prompt and type, “cd C:\Program Files\Common Files\Microsoft Lync Server 2010\Support”. Once you’re in the support directory, type:

dbimpexp.exe /user:<sipaddress> /sqlserver:domain-LYNCSQL1.domain.com\lync /hrxmlfile:E:\contacts\userfirst_last_contacts.xml

Your display will look like:

C:\Program Files\Common Files\Microsoft Lync Server 2010\Support>dbimpexp.exe /user:first.last@domain.com /sqlserver:domain-LYNCSQL1.domain.com\lync /hrxmlfile:E:\contacts\userfirst_last_contacts.xml
SQL Schema Version: 59
User Data Schema Version : 21
Exporting 1 Homed Resource(s) from database...
100% complete.
Export completed successfully.

You have now exported the user’s contact list.

In Lync 2013:

This functionality has been incorporated into Lync PowerShell. You simply use the following code:

Export-CsUserData -PoolFqdn "pool.domain.com" -FileName "e:\Contacts\First_Last_ExportedUserData.zip" -UserFilter first.last@domain.com

Importing Contacts:

In Lync 2010:

You can restore the contact list now using the process below:

From a command prompt in the C:\Program Files\Common Files\Microsoft Lync Server 2010\Support directory, type:

dbimpexp.exe /import /user:<sip address>/sqlserver:domain-LYNCSQL1.domain.com\lync /hrxmlfile:”<path where the xml file resides>” /restype:user

Your display will look like:

C:\Program Files\Common Files\Microsoft Lync Server 2010\Support>dbimpexp.exe /import /user:first.last@domain.com /sqlserver:domain-LYNCSQL1.domain.com\lync /hrxmlfile:E:\contacts\smcnamaracontacts.xml /restype:user
SQL Schema Version: 59
User Data Schema Version : 21
Importing Homed Resources into database...
1 Resource(s) imported.
Import completed successfully.

In Lync 2013:

This functionality has been incorporated into Lync PowerShell. You simply use the following code:

Import-CsUserData -PoolFqdn "pool.domain.com" -FileName "e:\contacts\First_Last_ExportedUserData.zip" -UserFilter first.last@domain.com

Export from Lync 2010 then Import to Lync 2013:

To import your 2010 contacts into 2013, you must convert the data, as 2013 uses a different format than 2010. Thankfully, there is a 2013 PowerShell cmdlet that does the heavy lifting. To Export a User's Contacts from 2010:

Export from 2010:

To export a user’s contact list, we’re going to use a Lync utility called “dbimpexp.exe”. This utility is included in the Resource Kit, so obviously, that must be installed before you can access the utility. Open a command prompt and type, “cd C:\Program Files\Common Files\Microsoft Lync Server 2010\Support”. Once you’re in the support directory, type:

dbimpexp.exe /user:<sipaddress> /sqlserver:domain-LYNCSQL1.domain.com\lync /hrxmlfile:E:\contacts\userfirst_last_contacts.xml

Your display will look like:

C:\Program Files\Common Files\Microsoft Lync Server 2010\Support>dbimpexp.exe /user:first.last@domain.com /sqlserver:domain-LYNCSQL1.domain.com\lync /hrxmlfile:E:\contacts\userfirst_last_contacts.xml
SQL Schema Version: 59
User Data Schema Version : 21
Exporting 1 Homed Resource(s) from database...
100% complete.
Export completed successfully.

Convert Your Contacts:

Copy the E:\contacts\userfirst_last_contacts.xml file to your 2013 Front End server, then run the following command:

Convert-CsUserData -InputFile "E:\contacts\userfirst_last_contacts.xml" -OutputFile "e:\contacts\First_Last_ExportedUserData.zip" -TargetVersion Current

Import Your Contacts to Lync 2013:

Run the following command to import the converted contact data:
Import-CsUserData -PoolFqdn "pool.domain.com" -FileName "e:\contacts\First_Last_ExportedUserData.zip" -UserFilter first.last@domain.com