I want to add a warning message at the top of the SP online site. For that i tried UserCustomActions using powershell, code is running without error but not working. I tried to add ribbon control that is working. I have enabled the allow script option in the admin site. Below i included the code for reference.
[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 [email protected]
Add-ScriptLinkAction -Context $context -ScriptBlock $ScriptBlock -Sequence 1000