【发布时间】:2020-11-24 07:57:26
【问题描述】:
我想在 SP 在线站点的顶部添加一条警告消息。为此,我使用 powershell 尝试了 UserCustomActions,代码运行没有错误但无法正常工作。我尝试添加正在工作的功能区控件。我在管理站点中启用了允许脚本选项。下面我包含了供参考的代码。
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Function Add-ScriptLinkAction([Microsoft.SharePoint.Client.ClientContext]$Context,[String]$ScriptBlock,[int]$Sequence)
{
$action = $Context.Site.UserCustomActions.Add();
$action.Location = "ScriptLink"
<#
if($ScriptSrc) {
$action.ScriptSrc = $ScriptSrc
}#>
if($ScriptBlock) {
$action.ScriptBlock = $ScriptBlock
}
$action.Sequence = $Sequence
$action.Name = "title"
$action.Title = "title"
$action.Update()
$Context.ExecuteQuery()
}
$siteUrl = 'https://stginfotechchennai.sharepoint.com/sites/ProductQualityReseachCenter'
$context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
# SPO credentials
$context.Credentials = Get-SPOCredentials -UserName username@domain.com
Add-ScriptLinkAction -Context $context -ScriptBlock $ScriptBlock -Sequence 1000
【问题讨论】:
标签: powershell sharepoint sharepoint-online csom