Script to migrate user accounts from Office Communications Server 2007/R2 to Lync Server 2010
There have been a lot of questions around is there a readily available powershell script to migrate user accounts from OCS 2007 R2 or OCS 2007 to Lync 2010. So I thought of writing one as there was none existing (atleast I couldnt find any :) ).
Script Funtionality:
a) Reads the SIP URI from a text file.
b) Moves the Legacy OCS User to Lync 2010
c) Logs the migration details in a log file.
How to run the script:
Step1 - Copy the below script text starting with BEGIN till END and save it in a text file. You can name the text file with whatever name you like. LyncMigration.txt in this case.
Step2 – Copy LyncMigration.txt on the Lync 2010 Server.
Step3 – Rename LyncMigration.txt to LyncMigration.ps1
Step4 - Create a folder named Logs in the same location where the script resides.
Step5 – Copy the SIP URI of the users to be migrated into a text file named OCSUsers.txt. Copy OCSUsers.txt in the same location where the script resides. The SIP URI should be in the format sip:user1@contoso.com.
NOTE: User identities can be specified in the below 4 formats
1) the user's SIP address;
2) the user's user principal name (UPN);
3) the user's domain name and logon name, in the form domain\logon (for example, litwareinc\kenmyer);
4) the user's Active Directory Domain Services display name (for example, Ken Myer). User Identities can also be reference by using the user’s Active Directory distinguished name.
Step5 – Replace the target with the actual FQDN of the Registrar pool where the user account should be homed. For example: -Target:pool01.contoso.com. This should be done in the below line in the script.
Move-CsLegacyUser -Identity:$OCSUsers[$Start] -Target:<FQDN of the Registrar pool>
Step6 - Start Lync Server Management Shell.
Step7 – Browse to the location of the script
Step8 – Run LyncMigration.ps1
Script Text:
################################################################# BEGIN #################################################################################################
#########################################################################################################################################################################
##
## Lync Migration Script
## ============================================
##
## Purpose:
##
## Migration of Legacy Office Communication Server users to Lync 2010
##
##
## Funtionality Overview:
##
## a) Reads the SIP URI from the OCSUsers.txt file.
## b) Moves the Legacy OCS User to Lync 2010
## c) Logs the migration details in a log file.
##
##
###########################################################################################################################################################################
###########################################################################################################################################################################
$Date=Get-Date
$Logfilepath= "logs\ProgressLog_{0}{1:d2}{2:d2}-{3:d2}{4:d2}{5:d2}" -f $date.year,$date.month,$date.day,$date.hour,$date.minute,$date.second + ".log"
################################################################################################################################
#
# Function: Logging
# =============
#
# Input Parameters:
# $logtext: The text string to be written to the console or to a log file
# $logtype: The type of message to be written: normal, error, or debug
#
# Purpose:
# - Writes a text string to the console and/or to log files depending on the type.
# type=cINFO: output goes to console and the normal log file
# type=cERROR: Output goes to Console, normal log file, and error log file
#
#
###############################################################################################################################
function logger( $logtext, $logtype )
{
switch($logtype)
{
cINFO
{
write-host $logtext -b black -f green
$logtext | Out-file $Logfilepath -append
}
cERROR
{
write-host "ERROR: " $logtext -b black -f red
"ERROR: " + $logtext | Out-file $logfilepath -append
}
csv
{
write-host $logtext -b black -f green
$logtext | Out-file $csvfilepath -append
}
}
}
## ----------------------------------------- End of Function "Logging" ---------------------------------------------------------
##################### Script Start ###################################
$OCSUsers = Get-Content ./OCSUsers.txt
for ($start = 0; $start -lt $OCSUsers.length; $start++)
{
write-host $OCSUsers[$Start]
$error.clear()
Move-CsLegacyUser -Identity:$OCSUsers[$Start] -Target:<FQDN of the Registrar pool> -Confirm:$False
if($error.count -gt 0)
{
logger ( "ERROR MOVING THE LEGACY OCS USER: " + $OCSUsers[$Start] + " : " + $error ) cERROR
}
else
{
logger ("LEGACY OCS USER MOVED SUCCESSFULLY : " + $OCSUsers[$Start] ) CINFO
}
}
##################### Script End ######################################
################################################################# END #################################################################################################
The -Confirm:$False switch can be removed if you want a promt before you migrate every account.
For any question you can reach out to us on the below information
Fahad Shaikh [MSFT] - fashaik@microsoft.com
Rajeev Krishnan [MSFT] - rajeevkr@microsoft.com
Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .
Comments
Anonymous
January 01, 2003
I would suggest uploading your script to the TechNet Scriptcenter so that others can find it easily. It is a great resource for all scripters and non-scripters out there. gallery.technet.microsoft.com/.../en-usAnonymous
January 01, 2003
The comment has been removedAnonymous
April 12, 2013
@david - Do you still need support with this ? If you do then please e-mail me at fashaik@microsoft.comAnonymous
April 12, 2013
I had this script running perfectly. However I've tried it again today and I'm getting the same errors as David. It cannot bind the parameter. Unsure what has gone wrongAnonymous
April 26, 2013
I am also seeing same error as David and Lindsay. Any fix for this.Anonymous
April 29, 2013
The OCSuser.txt file needs to have more than 2 x User listed for it to work.Anonymous
May 22, 2013
Working great for Lync 2013 too! Thanks!