Friday, 8 January 2016

Modify SIP Domain for Multiple Users

Hello Readers.  I hope this finds you well.

Recently, a customer asked me if it was possible to modify just the Domain in the SIP Address for multiple users in Lync. The answer is, of course, yes.  

One User
It is possible to modify just the SIP address for a single user called Elvis Presley.

Assign a few variables
$user = Get-CSUser -id "Elvis Presley"
$sipAddress = $user.SipAddress
$newDomain = $sipAddress -replace "@OldDomain.com","@NewDomain.com"


Then run a single line to make the change.
Set-CsUser -Identity $user.Identity -SipAddress $newDomain
Simple right?

All Users
What if you want to do it for all users?  That's also possible.

Start by "getting" all users and assigning them to a variable
$users = Get-CSUser
Then execute the following to make the change.
foreach ($user in $users)
{
  $sipAddress = $user.SipAddress
  $newDomain = $sipAddress -replace "@OldDomain.com","@NewDomain.com"
  Set-CsUser -Identity $user.Identity -SipAddress $newDomain
Specific Users
What if you only want to change the domain for a few users at a time?  For instance, only for users assigned to a specific Security Group.  That is also possible.

Start by "getting" a list of users that are a member of that security group.
$users = Get-ADGroupMember -Identity "Security Group" -Recursive | Select SamAccountName
Then execute the following to make the change.
foreach ($user in $users)
{
  $sipAddress = $user.SipAddress
  $newDomain = $sipAddress -replace "@OldDomain.com","@NewDomain.com"
  Set-CsUser -Identity $user.Identity -SipAddress $newDomain
}
Additional Filtering Options
There are many options for filtering users and returning a list.

By Email Domain
$users = Get-ADuser -Filter {(mail -like "*NewDomain.com")} | select name

By Organizational Unit 
$ou = Get-ADOrganizationalUnit -Filter {name -like "OU Name"} | select -ExpandProperty distinguishedname
$users = Get-ADUser -Filter * -SearchBase $ou | select -ExpandProperty name
 

Getting Clever
I couldn't just leave it there, so I wrote an interactive script that asks for the Security Group, old and new domains, makes the changes and produces logs and a list of next actions.

The Script is available on the TechNet Gallery.

If you find this post useful please take a moment to share.  Comments are welcome.

Thanks for reading.