Question

I need to change my default page of my site :

$assignment = Start-SPAssignment

    $web.RootFolder.WelcomePage ="Pages/"+ $page
    $web.RootFolder.Update()
    Stop-SPAssignment $assignment

But the welcome page still the same. My site is publish site, is there another solution .

Was it helpful?

Solution

You said that you are working with a publishing enabled site. As far as I know, the code you are using can't work on Publishing sites, you should use the .DefaultPage property provided by the PublishingSite class instead.

Try something like this:

$publishingWeb = 
    [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);

// note: pageFile is the acuall SPFile for the page, not just the url.
$publishingWeb.DefaultPage =$pageFile; 
$publishingWeb.Update();

Notice that you have to get a PublishingWeb first - think of it like a sort of wrapper that extends the normal SPWeb object and provides new functionalities specific for publishing enabled web sites.

OTHER TIPS

The problem with this is that everytime you instantiate $web.RootFolder it grabs a new object form the DB so your call to .Update() is actually doing nothing.

Try the following code:

$folder = $web.RootFolder
$folder.WelcomePage = "Pages/" + $page
$folder.Update()

This should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top