如何在 SharePoint 在线新式页面中使用 Powershell 脚本添加 Web 部件?
使用 PowerShell 脚本添加 Web 部件,我多次尝试这样做,但收到错误和警告。你能帮我解决这个问题吗?
您需要使用 PowerShell 模块 Pnp.PowerShell 中的命令 Add-PnPPageWebPart
代码示例:
$siteUrl = "https://my-tenant.sharepoit.com/sites/my-site"
Connect-PnPOnline -Url $siteUrl -Interactive
$pageUrl = "home.aspx"
$page = Get-PnPPage -Identity $pageUrl
Add-PnPPageTextPart -Page $page -Text "Hello world!"
Add-PnPPageWebPart -Page $page -DefaultWebPartType "List" -WebPartProperties @{ webRelativeListUrl = "/SitePages"}
控制台:结果:
你有什么问题吗?
你有哪些错误?