使用 PowerShell 添加和应用自定义页面布局时,它似乎只能在服务器上运行。当我尝试从外部打开页面时,我得到一个空白内容页面(母版页确实有效)。我工作的网站启用了发布功能。我用来应用的 PowerShell 代码:
$urlSiteRel = /sites/TheSiteName
$PageLayoutRelUrl = "$urlSiteRel/_catalogs/masterpage/MyPortalLayout.aspx"
# Get the Page URL
$PageName = "Portal.aspx"
# Get the Title of the Page which is going to get created
$PageTitle = "My Portal"
# Initialize the Site Object
$Site = Get-SPSite($urlSite)
# Get the Publishing Site based on the SPSite
$PubSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($Site)
# Get the SPWeb Object
$Web = Get-SPWeb $urlSite
# Initialize the PublishingWeb based on the SPWeb
$PubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($Web)
# Get the PageLayouts Installed on the Publishing Site
$Layouts = $PubSite.GetPageLayouts($False)
# Get our PageLayout
$PageLayout = $Layouts[$PageLayoutRelUrl]
# Create a new publishing page.
$Page = $PubWeb.AddPublishingPage($PageName, $PageLayout)
# Assign the Title for the Page
$Page.Title = $PageTitle
# Update the Page
$Page.Update();
# Check in the Page with Comments
$Page.CheckIn("Checkedin")
# Publish the Page With Comments
$Page.ListItem.File.Publish("Published")