使用PowerShell添加和应用自定义pagelayout时,它似乎只能在服务器上运行。当我尝试在外部打开页面时,我得到一个空白的内容页面(母版页确实有效)。我工作的网站已启用发布功能。我用来应用的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")
答案 0 :(得分:0)
我认为我$Layouts[$PageLayoutRelUrl]
你应该为你的页面布局而不是服务器相对提供web相对url。我的我没有使用尾随/
,
总结一下,请尝试
$PageLayoutRelUrl = "_catalogs/masterpage/MyPortalLayout.aspx"