SharePoint On-premises to On-premises migration – Important PowerShell commands at one place – Part 1


Hi All,

Greetings for the day πŸ™‚ LIFE IS BEAUTIFUL πŸ™‚

On every weekend we are starting sharing basic question and answers (may help to prepare interview , certifications, migration, help to understand basic concepts…) related to Microsoft cloud technologies (Azure, Azure AD, SharePoint, Microsoft 365, Teams, Power Platform and so on).

In last four weeks we shared interview questions about :

In this article we will discuss few important PowerShell CMDLETs which we require during SharePoint On-premises migrations

Pre-upgrade check before migration for MOSS / SharePoint 2007

stsadm.exe -o preupgradecheck 
  • Preupgradecheck will provide us the information regarding the SharePoint 2007 farm and actions that may be required to be taken before upgrading to SharePoint 2010 / SharePoint 2013
  • Once you get β€œOperation completed successfully”, it will launch the β€œSharePoint Products and Technologies Pre-Upgrade Check Report”
  • This report also copied at – %COMMONPROGRAMFILES%\Microsoft Shared\Web Server Extensions\12\Logs\
SharePoint On-premises to On-premises migration - Important PowerShell commands - STSADM -O PREUPGRADECHECK
Fig : SharePoint On-premises to On-premises migration – Important PowerShell commands – STSADM -O PREUPGRADECHECK

Delete the content db of the web application

stsadm -o deletecontentdb -url http://url -databasename

Detect Orphan sites or items – To know more about Orphan sites or items please have a look once our article – SharePoint 2013 – Basic questions and answers (help to prepare interviews, respective certifications and migration)

#detect orphaned items
stsadm -o databaserepair -url http://<site URL> -databasename <DB name that contains the orphan item>

#delete orphaned sites / items
stsadm -o databaserepair -url http://<site URL> -databasename <DB name  that contains the orphan item that is to be deleted> -deletecorruption

Get-SPContentDatabase – Returns specified content databases – Get-SPContentDatabase (SharePointServer) | Microsoft Docs

#returns content databases associated with web application
Get-SPContentDatabase -WebApplication https://webAppUrl

#returns content database which contains respective site collection
Get-SPContentDatabase -Site https://SiteCollectionUrl

Test-SPContentDatabaseTest-SPContentDatabase (SharePointServer) | Microsoft Docs

  • Verifies the content database for all our custom components against our web application
  • It checks Features, WebParts, SetUp files etc
  • This command may temporary block the content database
Test-SPContentDatabase -Name <DatabaseName> -WebApplication <URL>

$dataBase = Get-SPContentDatabase -site <SiteCollection URL>
Test-SPContentDatabase $dataBase -showrowcounts

Attaching content db to the web application – Creates new content database or adds a database

stsadm.exe -o addcontentdb -url <URL of SharePoint site> -databasename <dbname>

SharePoint 2010 visual upgrade using PowerShell

//Use this for entire webapplication

$webApp = Get-SPWebApplication ""
foreach ($site in $webApp.Sites){
       foreach($web in $site.AllWebs){
         $web.UIVersion = 4 #set it to 3 if we want SharePoint 2007 look & feel
       }#foreach($web in $site.AllWebs)
    }#foreach ($site in $webApp.Sites){

OR we could also use VisualUpgradeWebs() method

$webApp = Get-SPWebApplication ""
foreach ($site in $webApp.sites)


  • This PowerShell cmdlet attaches existing database to the Farm
  • This cmdlet also upgrades the database schema
     [-Name] <String>
     [-WebApplication] <WebAppURL>
     [-DatabaseServer <String>]
     [-MaxSiteCount <Int32>]

#To mount existing database to given web application URL. If upgrade requires it does upgrade as well
Mount-SPContentDatabase "dbname" -DatabaseServer "dbserver" -WebApplication "webappurl"

#To prevent any site upgrade
Mount-SPContentDatabase "dbname" -DatabaseServer "dbserver" -WebApplication 
"webappurl" -NoB2BSiteUpgrade


  • This CMDLET start upgrade process on respective site collection
Upgrade-SPSite [-Identity] <SiteCollectionURL>[-QueueOnly]


  • This CMDLET gets upgrade status information
  • This CMDLET gets information either for specific site collection or for content database
#Fetching upgrade status information for specific site collection
Get-SPSiteUpgradeSessionInfo -Site <SiteCollectionURL>

#fetching upgrade status information for al site collections from the given database
Get-SPSiteUpgradeSessionInfo -ContentDatabase <SPContentDatabasePipeBind>

Example : 
C:\PS>$db = Get-SPContentDatabase -Identity <db>
Get-SPSiteUpgradeSessionInfo -ContentDatabase $db

C:\PS>$site=Get-SPSite -Identity <mySiteURL>
Get-SPSiteUpgradeSessionInfo -Site $site

stsadm -o enumallwebs =>

stsadm -o enumallwebs -databaseserver <dbservername> -databasename <dbname>

The above command results as

<Sites Count="2">
  <Site Id="e2a114b8-80c9-41f6-87bf-3feddf2ad9b6" OwnerLogin="Domain\username" InSiteMap="False"> 
    <Webs Count="1">
      <Web Id="064d8e7b-b349-4693-bd67-dcefed3bf466" Url="/sites/site_name" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />
  <Site Id="a550224b9-79d9-32f6-87bf-4geddf2ad9b6" OwnerLogin="Domain\username" InSiteMap="True" HostHeader="">
    <Webs Count="1">
      <Web Id="12348e7b-c456-4693-bd67-efdegd3bf466" Url="/" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />


  • This command either run for specific one site collection or all site collections
  • This commands runs health checks
  • This command reports the health check rules which were run and provides the summary of the result
Test-SPSite -Identity  <RuleID>

<RuleID> is ID for a specific health rule check that you want to run.

To know more about health checks and rules please have a look once article – SharePoint On Premises migration – Basic question – answers / points / best practices / interview questions to know while migrating from MOSS / SharePoint 2010 to 2016


  • This command either run for specific one site collection or all site collections
  • This commands runs health checks
  • If any issues found this command automatically repairs those
Repair-SPSite -Identity  <RuleID>
<RuleID> is ID for a specific rule that you want to run.

I’ll stop here πŸ™‚ there are few more important commands which I’ll come up with part 2 πŸ™‚

If you feel some other commands which you know, need to be included in this collection kindly please share or put in comment box. We will definitely include πŸ™‚

Thanks for reading πŸ™‚ If its worth at least reading once, kindly please like and share πŸ™‚ SHARING IS CARING πŸ™‚

Share In Teams:

Enjoy the beautiful life πŸ™‚ Have a FUN πŸ™‚ HAVE A SAFE LIFE πŸ™‚ TAKE CARE πŸ™‚

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: