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.
$web.RootFolder.WelcomePage = $page
. Assuming$page
is the url of the page (ie.default.aspx
). Not sure if it will pick up pages fromPages
library, but this definitely works forSite Pages
.