5

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 = ?
8

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()
  • Perfect thanks. Only thing I changed: $pubWeb.GetAvailablePageLayouts() | ? {$_.Name -eq "MyPageLayout.aspx"} instead of $pageLayout[0] – Abe Miessler Dec 22 '11 at 21:38
  • 1
    Glad to help. :) – Russell Dec 22 '11 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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