Blog链接:https://blog.51cto.com/13969817 

如大家所了解的,在SharePoint Online中,Modern SharePoint 页面可以配置三种不同的页面布局:

·       Home Page Layout

·       Article Page Layout

·       Single Part App Page Layout

Home Page Layout,是在网站主页面上默认使用,用于现代网站的登录页面,没有顶部标题部分的页面布局;而Article Page Layout呢,是在Modern Page上默认使用,带有顶部横幅部分的页面;Single Part App Page Layout,www.则是隐藏顶部标题部分的页面,无法被终端用户使用浏览器编辑,只支持托管单个web part或者Microsoft Teams 应用程序。

那么如何通过PNP Powershell脚本在SharePoint Online中来改变页面布局以满足业务需求呢?

下方是相关示例代码,仅供参考

复制
Write-Host "Enter site collection URL:"
$siteCollectionURL = Read-Host
Write-Host "Enter page name:"
$PageName = Read-Host
Write-Host "Choose the page layout:"
Write-Host "1 - Home"
Write-Host "2 - Article"
Write-Host "3 - Single Web Part App"
$choice = Read-Host
if($choice -eq "1"){
    $choice = "Home"
}elseif($choice -eq "2"){
    $choice = "Article"
}elseif($choice -eq "3"){
    $choice = "SingleWebPartApp"
}
Connect-PnPOnline -Url $siteCollectionURL
Set-PnPClientSidePage -Identity $PageName -LayoutType $choice
06-19 00:46