Recently my colleague Michael Epping posted his original version of this script below to move users from 1 Lync 2010 pool to 2 Lync 2013 pools. You can find his post here. When he shared the script internally I felt the “need” to take it a step further and allow for a many to many relationship by the way of PowerShell arrays.
The script will ask for two values, the first being a comma separated list of the Lync 2013 servers (Destination). The second being a comma separated list of the Lync 2010 servers (Source). The Source / Destination Servers do not need to be just Lync 2010 or 2013 they are interchangeable in this case. From there the script is going to do all of the relevant math to equally distribute out our users evenly across all of the destination servers. So without further ado here is the script.
Usage Example:
PS C:LyncScripts> .CNCY-SplitCSPool.ps1
PS C:LyncScripts> SplitCSPool
cmdlet SplitCSPool at command pipeline position 1
Supply values for the following parameters:
Lync2013PoolArray: 2013pool1.demo.com,2013pool2.demo.com
Lync2010PoolArray: 2010pool1.demo.com,2010pool2.demo.com
PS C:LyncScripts>
Script:
#################################################################
## CNCY-SplitCSPool.ps1 ##
## ##
## Version 1.2 ##
## Created 8/28/2013 ##
## ##
## Developed By: Michael Epping Concurrency ##
## Modified By: Bill Hughes Concurrency ##
## ##
## ##
## This script is provided as-is, no warrenty is provided or implied. ##
## The author is NOT responsible for any damages or data loss that may occur ##
## through the use of this script. Always test, before using any script ##
## in a production environment. ##
## ##
################################################################
Function SplitCSPool {
#Request Parameter Input
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$Lync2013PoolArray,
[Parameter(Mandatory=$True)]
[string]$Lync2010PoolArray
)
#Script Block
#Convert source string $Lync2010PoolArray to multivalued array expecting , separator
$2010poolarray = $Lync2010PoolArray.Split(',')
#Initialize array variable to store all Lync users in all Lync source pools
$csusers = @()
foreach($lync2010pool in $2010poolarray)
{
#Get Lync Users with Primary Registar associated with Variable $Lync2010Pool
$csusers += Get-CsUser -Filter { RegistrarPool -eq $Lync2010Pool }
}
#Get Total Count of Users in Migration Batch
$csusercount = $csusers.Count
#Convert source string $Lync2013PoolArray to multivalued array expecting , separator
$poolarray = $Lync2013PoolArray.Split(',')
#Build loop counters and variables
$poolincrementcounter = 0
$poolcounter = 0
#Initialize array Variable to store User and pool mapping
$userpoolarray
#Determine number of users per destination pool split evenly across all pools
$splitby = (($csusers.Count)/($poolarray.Count))
#Loop through each user and map to a destination pool
foreach ($user in $csusers) {
$userpoolarray += @{$user = $poolarray[$poolcounter]}
if ($poolincrementcounter -lt ($splitby-1)) {$poolincrementcounter++}
else {$poolincrementcounter = 0;$poolcounter++;}
}
#Perform actual Lync Registrar Move
$userpoolarray.GetEnumerator() | ForEach-Object {
Move-CsUser -Identity $_.Key.Identity -Target $_.Value -Confirm:$false
}
}
Feel free to download this script here: CNCY-SplitCSPool_v1.2