CRM 2011: Moving organisations from one environment to another en masse

In our development environment we have quite a few CRM servers and every now and then we have a need to build new ones and migrate all of the organisations from one server to another.

I thought I would share the way that I do it in case you were faced with a similar challenge and needed a quick way of getting it done.

In this post I will be covering the method in which I move many CRM organisations from one environment to the other. The environments are pretty much exactly the same as one another so there is no migrating from Windows auth to IFD or anything like that and both servers are in the same domain.

Unfortunately I can't cover how to get powershell working with your CRM deployment in this post as it can be quite complicated depending on the way your server is configured. So this post assumes that you have a brand new CRM environment where everything is working and ready to receive CRM Organisations.

Please note that my CRM Servers are running WMF5 and CRM 2011 and my scripts are built to run in that environment.


Export the CRM org details from the source CRM server.

  1. Login to your Source CRM server as a deployment admin and open an elevated PowerShell window.
  2. run the following command: Add-PSSnapin Microsoft.crm.powershell
  3. Get-CrmOrganization | Export-Clixml -Path C:\CRMOrgs.xml
  4. Copy the CRMOrgs.xml file to the destination CRM server. We will need that for later.

Backup all of the CRM organisation databases.

I find that the quickest way to take all the needed backups is to just use a SQL maintenance plan.

If you know how to make a maintenance plan and run it skip ahead to the next section called Restore the SQL Databases, we are just backing up the databases here.

  1. Open SQL Management Studio and connect to your server instance.
  2. Expand Maintenance Plans
  3. Right click --> New Maintenance Plan
  4. Give it a name and click OK.
  5. From the Toolbox menu on the left, drag and drop the Backup Database Task to the Maintenance plan window.
  6. Right Click the Backup Task --> Edit.
  7. Make sure the backup Type is "Full" and that Compress Backup is ticked.
    (if you can't see the Compress Backup option go and make sure that it is turned on in the SQL server options. it is under Database Settings. Trust me, this will make the backups run much faster and the restores run faster.)
  8. Click the drop down for Databases, select the "These Databases" Radio button and select all of the org_MSCRM databases. Don't take the MSCRM_Config or any of the non CRM databases.
  9. Under Destination, specify a network location that both SQL service users have access to read and write to and click OK.
  10. Save the maintenance plan and hit the refresh button in the Object explorer.
  11. Right click your maintenance plan and click Execute.
  12. This might take a while so go get a coffee or something.

Create a Script to Restore all of the SQL Databases

  1. Download this script and Open it in PowerShell ISE to edit it.
  2. Change the value of $BackupFilesLocation to point to the folder where you stored your backups.
  3. Run the Script.
  4. Go to the $BackupFilesLocation and look for a file called FileList.csv and open it with Excel.
  5. At the very bottom of the PS1 file, you will see an excel formula, copy it into C2 and change the File Paths that are specified after MOVE 'mscrm' TO and MOVE 'mscrm_log' TO so that the SQL MDF and LDF files are restored to the correct location on your new SQL server.
  6. Check that the File names and database names in the formula make sense and fill down that formula for each DB listed in the CSV.

The values in Column C combined are essentially the script that we will use to restore the databases and we will need them in the next step.

Restore the SQL Databases to the new SQL server.

  1. Open SQL Management Studio and connect to your new SQL server.
  2. Click on New Query in the ribbon menu.
  3. Copy all of the values from Column C in our spreadsheet into the New Query window.
  4. Execute the query. All of your SQL Databases will eventually restore.

This could take some time.

Import the CRM Organisations

Login to your new CRM server as a deployment administrator and open an elevated PowerShell ISE window.

Download this script and edit it in ISE. You will need to update the following script parameters with the values that suit your environment:

  • $orgs
  • $SQLServerName
  • $SRSurl

After you run this, you can keep on running Line 9 over and over just to see how many imports are left to do. But that is pretty much it! After the jobs are completed, your CRM will have all of the CRM organisations in it and you can start letting users access it. If you are running CRM in IFD mode you will still have to update the DNS records but I won't go through that here.

If you have a huge amount of DNS records to modify though, I will give you a hint on how you can automate it. The FederationMetadata.xml file that the CRM generates has every CNAME you will need to create for that deployment. Have fun!