Showing posts with label Lync. Show all posts
Showing posts with label Lync. Show all posts

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

Friday, March 15, 2013

List A User's Response Group Memberships

We just had an issue where a response group in Lync was not working properly. While troubleshooting, we discovered that the user to whom the response group pointed had recently been married and had her name changed. Per normal process, her AD account, email address and SIP name were changed to her new name. This caused an issue with the response group, however. Since there was a gap in the process, and we had no procedure in place for checking the user’s membership in response groups, the group was trying to transfer a call to a now non-existent SIP address. So, that means whenever we change an account we must know if the user is Enterprise Voice enabled, and if they are, we must also know if they belong to any response groups. Unfortunately, there is no clean way to find that membership in the Lync Control Panel. You would have to open each response group and look at its membership one at a time to see if the user was a member. To get around this, you’ll have to RDP into a Lync  Server and open a Lync Powershell session and enter the following command:

get-csrgsagentgroup | Where-Object {$_.AgentsByUri -like "sip:first.last@spx.com"} | Select name

See the example below to illustrate what it looks like and what the results would be:
This will give you a list of response groups the user is a member of. You can then make the appropriate changes to the groups, if any.

Thursday, August 9, 2012

Enabling users for Lync Enterprise Voice

I am now piloting Lync Enterprise Voice for my company, and we will be enabling many users moving forward. I have written the following script to:
  1. Move users to a "Branch" Pool
  2. Enable them for Voice
  3. Grant a voice policy
The script is meant to be run, eventually, by local IT at the branch location. It takes input from a .csv file structured like:

LineURI,Name,ADUSERNAME
tel:+11112345678;ext=5678,Jon Smith,jsmith
tel:+11112347485;ext=7485,Nasir Patel,npatel
tel:+11112347518;ext=7518,Tom Jones,tjones


You can tailor the LineURI as appropriate for your organization.

The script, when launched, asks for the target pool, the file with the information and the voice policy to be granted:




That's all you need to do. Well, that and then enable them in whatever voicemail solution you are employing...

The code is as follows. I will make it more elegant as time allows.

<# 
.SYNOPSIS 
  Queries admin for Pool, Input File and Voice Policy for the users. Then
  reads info in Input file, moves users to appropriate pool, enables Enterprise
  Voice for them, and grants the entered Voice Policy.

.NOTES 
    Version           : 1

      Lync Version  : 2010 through CU6
    Author(s)      : Sean William McNamara (
sean.mcnamara@spx.com)
    Dedicated Post  :
http://unicomsta.blogspot.com/
    Disclaimer     : Test thoroughly and use at your own risk. If you don't test it, and you break stuff, it isn't MY fault.
   
.LINK 
    http://unicomsta.blogspot.com/2012/08/enabling-users-for-lync-enterprise-voice.html

.EXAMPLE
  .\Enable-EvUsers.ps1
#>
#initialize variables
$poolfqdn = read-host "Enter new pool FQDN to move users to "
$InputFileName = read-host "Enter filename for user data "
$VoicePolicy = read-host "Enter Voice Policy Name "


#read data for Accounts
$AccountData = Import-Csv $InputFileName

#move users to correct registrar pool
foreach ($item in $AccountData)
{ write-host -fore yellow "Moving" $item.NAME "... "
  move-csuser -identity $item.ADUSERNAME -target $poolfqdn -confirm:$false
}

write-host
write-host -fore green "Move completed"
write-host
#enable EV and set URI

foreach ($item in $AccountData)
{ write-host -fore yellow "Enabling Voice for " $item.NAME "... "
  Set-CsUser -Identity $item.adusername -EnterpriseVoiceEnabled $true -LineURI $item.LineURI
}

write-host
write-host -fore green "Enterprise Voice Enabled"
write-host

#grant Voice Policy
foreach ($item in $AccountData)
{ write-host -fore yellow "Granting Voice Policy "$VoicePolicy" to " $item.NAME " ... "
  Grant-CsVoicePolicy -Identity $item.adusername -PolicyName $VoicePolicy
}

write-host
write-host -fore green "Voice Policies Granted"
write-host

Tuesday, July 17, 2012

View Lync Client Configuration

You can easily view the configuration information of the Lync 2010 client by following these simple steps.
  • Hold the Control key down while right-clicking the green Lync client icon in the notification area.

  • This will enable the Configuration Information menu option. Click it and you will see a pop-up window that displays all the Lync 2010 configuration information for the client.

Trouble Transferring and Answering Calls from Lync Attendant Console

At one of my sites where Lync has been deployed as a replacement for a PBX I ran into an issue with the receptionist being able to answer and or transfer calls from the PSTN. Calls would come in, and about 30% would be problematic. Some, she couldn't answer at all, others, would either drop when she tried to transfer them, or would connect only after 45-60 seconds of silence, by which time, the caller would assume the call had been dropped and hang up. As you can imagine, this was having a significant impact on our ability to do business.

I researched online, and didn't really find any reasonable explanations or solutions. So, I opened as case with Microsoft Premier Support, and as we were working through testing, pulling logs from the SBA, Front End Servers and the receptionist's Attendant Console, we determined that what was happening was that the SIP REFER method was failing. Information on what the SIP REFER method does can be found at: RFC 3515 - SIP Refer Method..

After some more research, I discovered that SIP REFER is enabled by default in Lync, and the Gateway we have deployed, the NET UX 2000, does not support SIP Refer. I found this article on NET's website that explains how to disable SIP REFER, and as a result, Media Bypass: Disable Refer Support (required for Transfer).

The Microsoft article on this is found here: Configure a Trunk Without Media Bypass. The MS article lacks a great deal of information, and barely mentions the SIP REFER option.