I have a bunch of sites in which I would like to change the default Page Layout.

Is there a way to set this to a custom Page Layout using powershell? (The page layout is already on all the sites)

So far I've come up with this, but I'm not sure how to proceed:

$web = Get-SPWeb -Identity "http://whatever/"
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pubWeb.DefaultPageLayout = ?
link|improve this question

feedback

1 Answer

up vote 4 down vote accepted

Yes you can set the default page layout using PowerShell.

The method you are looking for is PublishingWeb.SetDefaultPageLayout() (see MSDN here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingweb.setdefaultpagelayout.aspx)

$site = new-Object SPSite http://mysite.com
$web = $site.RootWeb
$pweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)

# This code (as an example) uses the first layout as the default.
$layouts = $pweb.GetAvailablePageLayouts()
$pweb.SetDefaultPageLayout($layouts[0], $false)
$pweb.Update()

$web.Dispose()
link|improve this answer
Perfect thanks. Only thing I changed: $pubWeb.GetAvailablePageLayouts() | ? {$_.Name -eq "MyPageLayout.aspx"} instead of $pageLayout[0] – Abe Miessler Dec 22 '11 at 21:38
Glad to help. :) – Russell Dec 22 '11 at 21:40
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.