Schedule Changes to Response Group settings

Ever have the need to forward calls to a destination on a schedule? Well, it’s a situation I came across several times now. There are several ways to solve this matter with Microsoft Lync 2013. In this post, I’ll describe one.

One office number needs to be redirected to a person, including it’s mobile phone number. Here’s the tricky part: every week, it’ll need to be redirected to another employee.
Employees are using simultaneously ringing and/or call forwarding to their mobile phone numbers.

To solve this situation, one can use Response Groups and use call overflow on the configured queue. This way, the configuration is dynamic enough to adapt additional configuration. Such as different day/night configuration, announcement(s) et cetera.
Configuration can be changed by entitled employees using the Response Group Manager rights.

Situation 1

However, still no solution for the first requirement – an automatic change every week! For this, I decided to write a script.

Script

What this script will do is the following:

  1. Read a bunch of variables and calculate the current week number
  2. read out a CSV file, filled with week numbers and the SIP addresses of the corresponding employees.
  3. filter out the employee´s SIP address from the CSV file, based on the current week number
  4. Change the RGS Queue Call Overflow settings to forward calls to the employee´s SIP Address.

All of this with some error handling. The script is intended to run as a scheduled task, writing success or error to the event logs.

#####################################################################
#####################################################################
#####################################################################
####           Schedule Lync RGS Settings Script                 ####
####                                                             ####
####          Written by  : Louis Herber                         ####
####          More Info   : https://ms-uc.herber.co               ####
####          Version     : 1.0                                  ####
####                                                             ####          
####  This script will change the Lync Response Group Queues.    #### 
####  It will lookup a CSV File, based on the weeknumber it      #### 
####  will change the overflow action to a new value.            #### 
####                                                             #### 
#####################################################################
#####################################################################
#####################################################################

#################################################
### Part 1: Define params and load Lync PS    ###
#################################################

# use parameters if defined, if not use defaults as defined here

Param(
[string]$ApplicationServer="FQDN Of Front-end(s) with RGS",
[string]$RgsQueue="(Default) queue name",
[string]$CSVFilename="CSV file location"
)

# Import Lync Module

import-module Lync

#################################################
### Part 2: Define functions and Error Log    ###
#################################################

# Get-ExtendedDate Function

function Get-ExtendedDate
{
 $x = get-date
  add-member -MemberType scriptmethod -name GetWeekOfYear `
     -value {get-date -uformat %V} -inputobject $x 
 $x
 } 

# Create Eventlog Source if not available yet
$EvLog = get-eventlog -LogName Application
if ($EvLog.source -cnotcontains "Lync RGS Queue Modifier") {New-EventLog -LogName Application -Source "Lync RGS Queue Modifier"}


#################################################
### Part 3: Import CSV and def. weeknumber    ###
### compare it with CSV and load SIP dest.    ###
#################################################

## Import CSV File
$CSV = Import-Csv $CSVFilename

## Get Current Weeknumber for comparison
$CurrentWeekNumber = (Get-ExtendedDate).getWeekOfYear()

## Get SIP URI for this week from CSV File
$ForwardActionThisWeek = $CSV | Where-Object {$_.weeknumber -eq $CurrentWeekNumber} 
$SIP = $ForwardActionThisWeek.SIP

#################################################
### Part 4: define error texts and vars       ###
#################################################


#### Define Error Texts
$ErrorText = “Lync RGS Queue Modifier has not been completed successfully due to an error in the Lync script execution. Variables Used are:"
$InformText = “Lync RGS Queue Modifier has been completed successfully and the RQS Queue has been changed. Variables Used are:"
$ErrorVariables = “Lync RGS Queue Modifier has not been completed successfully due to an error in the variables:"
$variables = 
"`n" +
" Current Week Number: " + $CurrentWeekNumber + "`n" +
" Current AppServer: " + $ApplicationServer +  "`n" +
" Current RgsQueue: " + $RGSQueue +  "`n" +
" Current CSV Filename: " + $CSVFilename + "`n" +
" Current Fwd action: " + $ForwardActionThisWeek + "`n" +
" Current SIP: " + $SIP + "`n"


#################################################
### Part 5: Perform actual Script             ###
### Performing script If all Variables are OK ###
### if not, skipping to ErrorHandling section ###
#################################################

if ($SIP -ne $null)
{

$Queue = Get-CsRgsqueue -identity "service:applicationserver:$ApplicationServer" -name $RgsQueue
If ($? -eq $false){$LogAsError=$true} 

$Caction = New-CsRgsCallAction -Action TransferToUri -Uri "sip:$SIP"
If ($? -eq $false){$LogAsError=$true} 

$Queue.OverflowAction = $Caction
If ($? -eq $false){$LogAsError=$true}

$Queue.OverflowCandidate = "NewestCall"
If ($? -eq $false){$LogAsError=$true}

$Queue.OverflowThreshold = 0
If ($? -eq $false){$LogAsError=$true}

Set-CsRgsQueue -Instance $Queue
If ($? -eq $false){$LogAsError=$true} 


### ErrorHandling of script ###

If ($LogAsError -eq $true)
{
write-host $ErrorText $variables "`n" -ForegroundColor red
$ErrorValue=$error[0].Exception
$ErrorValue2=$error[0].Exception.StackTrace
Write-EventLog –LogName Application –Source “Lync RGS Queue Modifier” –EntryType error –EventID 7778 -message "$ErrorText $variables `n $ErrorValue 'n $ErrorValue2"
}
Else
{
write-host $InformText $variables -ForegroundColor green
Write-EventLog –LogName Application –Source “Lync RGS Queue Modifier” –EntryType information –EventID 7777 -message "$InformText $variables"
}
}
Else
{
write-host $errortext $variables -ForegroundColor red
Write-EventLog –LogName Application –Source “Lync RGS Queue Modifier” –EntryType error –EventID 7778 -message "$ErrorVariables $variables"
}

Either use the command/line switches, and/or enter static/default values into the first part of the script.
Then, create or use a service account (with appropriate rights like CSAdministrator or RGSmanager, and local admin / `log on as a batch job` rights) in the AD, and use it for creating a scheduled task.

RGS-Schedule_CreateTask-1

add powershell.exe as the executable, with (some of the) following line as command parameters:

-file C:\SCRIPTS\ForwardToSIPURI.ps1 -executionpolicy Bypass -ApplicationServer <FQDN> -CSVFilename <Path to CSV> -RgsQueue "<RGS Queue Name>"

RGS-Schedule_CreateTask-3 RGS-Schedule_CreateTask-4

Now, schedule it for every week. Result would be something similar to this:

RGS-Schedule_TaskOverview-1

And finally, if you haven’t done so already, create the CSV containing all week numbers and corresponding SIP addresses.

RGS-Schedule_ActionsCSV

And you´re done!

Changing the script

As mentioned before, using RGS will allow this script to be more flexible. For instance, when you want it to be used as a normal response group during office hours, but only use the SIP forwarding during out of business hours. As a bonus, you could configure a timeout during office hours to make sure each call is answered.

Situation 2

Just by changing lines 96-112:

$Workfl = Get-CsRgsWorkflow -identity "service:applicationserver:$ApplicationServer" -name $RgsQueue # or change to $RgsWorkfl and define it in params
If ($? -eq $false){$LogAsError=$true} 

$Caction = New-CsRgsCallAction -Action TransferToUri -Uri "sip:$SIP"
If ($? -eq $false){$LogAsError=$true} 

$Workfl.NonBusinessHoursAction = $Caction
If ($? -eq $false){$LogAsError=$true}

Set-CsRgsWorkflow -Instance $Workfl
If ($? -eq $false){$LogAsError=$true} 



$Queue = Get-CsRgsqueue -identity "service:applicationserver:$ApplicationServer" -name $RgsQueue
If ($? -eq $false){$LogAsError=$true} 

$Queue.TimeOutAction = $Caction
If ($? -eq $false){$LogAsError=$true}

$Queue.TimeOutThreshold = 60
If ($? -eq $false){$LogAsError=$true}

Set-CsRgsQueue -Instance $Queue
If ($? -eq $false){$LogAsError=$true}

 

 

This might not be rocket science, though it can save a lot of (manual) work and act as a template for any scheduled changes to Lync Response Groups!

 

3 Comments

  1. Not sure if you’ve tested this yet, but does this still work with the Skype for Business with the July 2015 updates?  I feel like the July 2015 updates broke this sort of setup.

    1. Hello Willie, it has indeed to do with overflow of 0 calls. This still works in Skype for Business with Update, however, now it is required to have a agent group in the queue (and probably an agent in the agent group).

Leave a Reply to Willie Cancel reply

Your email address will not be published. Required fields are marked *