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? <pausing for dramatic effect> You use Power-Shell!

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!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s