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 :
- Azure =>https://knowledge-junction.in/2021/05/15/azure-basic-questions-and-answers-help-to-prepare-interviews-and-respective-certifications/
- Azure AD => https://knowledge-junction.in/2021/05/02/azure-ad-basic-questions-and-answers-help-to-prepare-interviews-and-respective-certifications/
- SharePoint 2013 =>https://knowledge-junction.in/2021/05/08/sharepoint-2013-basic-questions-and-answers-help-to-prepare-interviews-respective-certifications-and-migration/
- SharePoint On Premises migration => https://knowledge-junction.in/2021/05/22/sharepoint-on-premises-migration-basic-question-answers-points-best-practices-interview-questions-to-know-while-migrating-from-moss-sharepoint-2010-to-2016/
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\

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-SPContentDatabase – Test-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 "http://knowledgejunction.mycompany.com"
foreach ($site in $webApp.Sites){
foreach($web in $site.AllWebs){
$web.UIVersion = 4 #set it to 3 if we want SharePoint 2007 look & feel
$web.Update()
}#foreach($web in $site.AllWebs)
}#foreach ($site in $webApp.Sites){
OR we could also use VisualUpgradeWebs() method
$webApp = Get-SPWebApplication "http://knowledgejunction.mycompany.com"
foreach ($site in $webApp.sites)
{
$site.VisualUpgradeWebs()
}
Mount-SPContentDatabase
- This PowerShell cmdlet attaches existing database to the Farm
- This cmdlet also upgrades the database schema
Mount-SPContentDatabase
[-Name] <String>
[-WebApplication] <WebAppURL>
[-DatabaseServer <String>]
[-MaxSiteCount <Int32>]
[-NoB2BSiteUpgrade]
[-SkipSiteUpgrade]
#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
Upgrade-SPSite
- This CMDLET start upgrade process on respective site collection
Upgrade-SPSite [-Identity] <SiteCollectionURL>[-QueueOnly]
Get-SPSiteUpgrdeSessionInfo
- 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>
[-ShowCompleted]
[-ShowFailed]
[-ShowInProgress]
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 =>https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-2007-products-and-technologies/dd789634(v=office.12)
- This is one of the important stsadm operation during migration
- Displays the IDs and site map status for all site collections and subsites in the content database
- This operation requires MOSS with SP2
- To know more about SiteMap – please have a look once article – SharePoint 2013 – Basic questions and answers (help to prepare interviews, respective certifications and migration)
- This operation also used to find orphan items from the database
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" />
</Webs>
</Site>
<Site Id="a550224b9-79d9-32f6-87bf-4geddf2ad9b6" OwnerLogin="Domain\username" InSiteMap="True" HostHeader="www.knoweldgejunction.com">
<Webs Count="1">
<Web Id="12348e7b-c456-4693-bd67-efdegd3bf466" Url="/" LanguageId="1033" TemplateName="STS#0" TemplateId="1" />
</Webs>
</Site>
</Sites>
Test-SPSite
- 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
Repair-SPSite
- 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 🙂

1 Response
[…] In previous article we shared few important required POWERSHELL CMDLETS. – SharePoint On-premises to On-premises migration – Important PowerShell commands at one place – P… […]