Tuesday, August 7, 2012

How To Change the Welcome Page / Homepage in SharePoint 2010 Programmatically

When exporting and importing sites throughout SharePoint 2010 that are upgraded sites from SharePoint 2007, you probably noticed that the homepage for the imported site is defaulted to SharePoint 2010′s wiki-style page at /SitePages/Home.aspx. However, until you start using these new pages you may want to revert or keep the homepage as the default.aspx page. To do this manually, you need to go to Site Actions > Site Settings > Look and Feel > Welcome Page. However, this Welcome Page link is only available for those sites where the Publishing feature is activated at the Site Collection and Site level.



This could be pretty tedious if you have to do this for every site in the web application. So, if you need to do this fast for multiple sites and don’t have direct access to the Welcome Page link, what do you do? You use PowerShell!
Below is a script I created that will prompt to enter in the Web Application and Welcome Page and then loop through each site in the Web Application and set the Welcome Page. Save this as a .ps1 file and run it from the SharePoint 2010 Management Shell:






$webapp = Read-Host "Enter Web Application"
$welcomepage = Read-Host "Enter Welcome Page"
$webs = Get-SPSite -WebApplication $webapp -Limit All | Get-SPWeb -Limit All
foreach ($web in $webs){
   $rootFolder = $web.RootFolder
   $rootFolder.WelcomePage = $welcomepage
   Write-Host "Setting"$web.Title"homepage to"$welcomepage
   $rootFolder.Update()
   $web.Dispose()
}
 
 
Now, navigate back to a site and see that the homepage is now set to the given page!

2 comments:

  1. Nice post. Here is one more post explains the same..
    http://sureshpydi.blogspot.in/2014/03/change-default-homewelcome-page-in.html

    ReplyDelete
  2. Thanks for this piece of information. I have just signed up for a free SharePoint site with http://www.cloudappsportal.com.

    ReplyDelete