Skip to content
September 18, 2012 / red1s

PowerShell Script for auto updating MOSS 2007 databases to SharePoint 2010


Recently we went through a repetitive upgrade process for multiple site collections.

The problem with having multiple site collections is that there are multiple databases to upgrade.

Within my project there were over 20+ databases.

clip_image001

I therefore decided to build/modify the following PowerShell script to assist me in doing the job:

Based on the switches you can add further functional items to the script, alternatively you can loop the function to iterate through another file (possibly csv) to iterate through all your databases

function main()

{

Clear-Host;

Write-Host

Write-Host ""

Write-Host "1. Press ‘1’ to attach and upgrade a 2007 database";

Write-Host ""

$input = Read-Host "Enter a number for an option"

switch ($input)

{

"1" {UpgradeDatabase}

}

}

function UpgradeDatabase()

{

$webAppUrl = Read-Host "Web application URL"

$contentDbName = Read-Host "Content Database Name"

$webApp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup($webAppUrl)

Write-Host "Mounting database $contentDbName";

Mount-SPContentDatabase -Name $contentDbName -WebApplication $webApp

Write-Host "Mounting complete";

$contentDb = Get-SPContentDatabase -Identity $contentDbName

Write-Host "Applying Corrective Action";

ApplyCorrectiveChanges $contentDb

}

 

As with using the Mount-SPContentDatabase PowerShell command the UI will request the following variables, being web application and Content Database Name to get started. But as mentioned if you loop through this you’ll be able to iteratively do your entire set of site collections (obviously if there are no hiccups along the way)

Leave a comment