Script Repository

Add user to Lync Response Group Agent Group

March 20, 2017

The script adds the user on which it is executed to a Lync Response Group Agent Group.

You can need to execute the script via a Business Rule, Custom Command or Scheduled Task only. To add it to a rule, command or task, use the Run a program or PowerShell script action.


  • $lyncServer - specifies the Fully Qualified Domain Name (FQDN) of your Lync Server;
  • $serviceIdentity - specifies the identity of the service where the Response Group agent group is hosted;
  • $agentGroupName - specifies the name of the Response Group Agent Group.
Edit Remove
$lyncServer = "" # TODO: Modify me
$serviceIdentity = "" # TODO: Modify me
$agentGroupName = "Help Desk" # TODO: modify me

# Get the user's SIP address
$mailParams = $Context.TargetObject.GetMailParameters()
$emailAddresses = $mailParams.EmailAddresses
$sipAddresses = $emailAddresses.GetAddressesByPrefix("sip")

if ($sipAddresses.Length -eq 0)
    $Context.LogMessage("Cannot add the user to the specified Role Group Agent Group because the user doesn't have a SIP address.", "Error")

    # Connect to the Lync Server
    $sessionOptions = New-PSSessionOption -SkipRevocationCheck -SkipCACheck -SkipCNCheck
    $session = New-PSSession -ConnectionUri https://$lyncServer/ocspowershell `
        -SessionOption $sessionOptions -Authentication NegotiateWithImplicitCredential

    Import-PSSession -session $session

    # Get the Role Group Agent Group
    $agentgroup = Get-CsRgsAgentGroup -Identity $serviceIdentity -Name $agentGroupName

    # Add the user
    $agentgroup.AgentsByUri.Add("sip:" + ($sipAddresses[0]).Address)
    Set-CsRgsAgentGroup -Instance $agentgroup
    # Close connection to the Lync Server
    Remove-PSSession -Session $session

Comments ( 0 )
No results found.
Leave a comment

Related Scripts