Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 = ?
share|improve this question
add comment

1 Answer 1

up vote 6 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()
share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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