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.


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"

$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 

1 Answer 1


For modern page,we need to use spfx extension to add js file to page.If your code is ok,classic page should work well.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.