Showing posts with label homepage. Show all posts
Showing posts with label homepage. Show all posts

Tuesday, March 11, 2014

Change default home/welcome page in SharePoint site using PowerShell commands

We can change SharePoint default home page in different ways as using Site settings if publishing feature already enabled, SharePoint object model code, Using SharePoint designer and PowerShell commands.
We can change the home page by running following PowerShell commands,

Get the Site details by using Get-SPSite command and web by using OpenWeb() method.

$objSite = Get-SPSite SiteURL
$objWeb = $objSite.OpenWeb(“Sub site”)

Get the root folder for the web by using RootFolder property

$rootFolder = $objWeb.RootFolder

Change the home page by assigning Welcomepage property as shown below

$rootFolder.Welcomepage = “SitePages/SureshHomePage.aspx
$rootFolder.update()

After updating the page, we have to dispose the site and web objects because that objects are created newly.

$objWeb.dispose()
$objSite.dispose()

By combing the all the commands we can see the script as

$objSite = Get-SPSite SiteURL
$objWeb = $objSite.OpenWeb(“Sub site”)
$rootFolder = $objWeb.RootFolder
$rootFolder.Welcomepage = “SitePages/SureshHomePage.aspx
$rootFolder.update()
$objWeb.dispose()
$objSite.dispose()