Personal Web & Sample Site
Skip Navigation Links
About Me |
| Contact Us
Migration with PowerShell
Rating: 7 user(s) have rated this article Average rating: 5.0
Posted by: joet, on 4/19/2012, in category "SharePoint"
Views: this article has been read 4837 times
Location: Houston, Tx, United States
Abstract: I am currently on a migration project right now and I want to document steps, tricks, and PowerShell cmdlets.

So far I haven't been part of an in-place migration and I hope it never happens. I am currently working on a migration project and before I start the first thing I ask is, how much customization do you have in your environment? Man! As always the response is either very little or none at all. They either don't have a clue and don't want to admit it, or its underestimated and it always turns out to be more than enough for failure. Ok, the clients tells me there's hardly any at all, so the second thing I do is run the stsadm.exe -o preupgradechecker and determine how much customization there really is. After fixing and deleting I run the stsadm.exe -o databaserepair command and make sure there are no orphan site and I make sure that all 3rd party custom webparts have been deleted Then I start backing up databases in read-only and then move them over to the new MSSQL 2008 servers. I create new DB's with the same name and then restore these backups making sure that I have set the correct options. Depending on the size of your DB this may take a while but afterwards, I then proceed to take them out of read-only mode. After I have restored the dtabases I also make sure that the farm account is mapped to the new databases and assign db_owner. The next step is to attach them to the web application and this is the actual migration process when you run the PowerShell Mount cmdlet. But this post is mainly for the purpose of listing all of the PowerShell cmlets I had to use during this migration. Run the spugradechecker first and get a list of all that needs to be fixed and taken care of before migrating databases, especially orphaned sites. After running the -Mount cmdlet, run the Test-SPContentDatabase cmdlet and get a report on all errors and warnings. This report is the best one and very helpful.. If you see that the report is listing many errors rest assure that the migration process did not complete and you will have to go back and fix or delete those features that include web parts and then rerun the migration script. I also had to use a utillity from CodePlex calle "Easy SharePoint WebPart type ID Generator" that would help me identify those hard to find webparts.

You might need to delete sites for clean up and you can use the following script:


C:\stsadm.exe –o databaserepair –url http://ushou-sharep01 –databasename WSS_Content –deletecorruption

stsadm -o deletesite -force -siteid 40ca628e-8d7c-461b-9340-c5bb518cf399 -databasename wss_content_ep -databaseserver sql08W2008X64

stsadm.exe –o enumallwebs –databasename YourSQLName –databaseserver YourSQLServerName

Your asking; how do you get the GUID for the site? You simply enumb sites that prints out that information


First of all, don't forget to Add-PSSnapin Microsoft.SharePoint.PowerShell if you haven't already done so.

Mount-SPContentDatabase "<ContentDb>" -DatabaseServer "<DbServer>" -WebApplication http://SiteName

Once the migration process has completed you may want to run the following script and pipe it into a text or xml file.

Test-SPContentDatabase -name WSS_Content -webapplication http://ushou-sp10wfe01

Add-SPSolution -LiteralPath C:\Solutions\SmilingGoat.SharePoint.WebParts.Rss.wsp

I had to backup a site collection from one database and then restore it into another with this cmdlet:


Backup-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak


Restore-SPSite http://server_name/sites/site_name -Path C:\Backup\site_name.bak

When I ran the Test-SPContentDatabase the report I got was huge (70 pages back-to-back) and it was hard to read so I had to pipe several cmlets to make it more readable like this:

Test-SpContentDatabase -name WSS_Content_SP2 –webapplication http://webapp -serverinstance SQLServer | ConvertTo-Html | Out-file c:\files\TestSPContent_db2.htm, or .cvs if you prefer.

I'll keep updating this post with more PowerShell cmdlets at a later time.

How would you rate this article?

User Feedback

Post your comment
Insert Cancel

Copyright © 2013 Jose M. Tamez
Last Updated August 18th 2013