Add-PnPJavaScriptBlock

Adds a link to a JavaScript snippet/block to a web or site collection

Syntax

Add-PnPJavaScriptBlock
   -Name <String>
                         -Script <String>
                         [-Sequence <Int>]
                         [-Scope <CustomActionScope>]
                         [-Web <WebPipeBind>]
                         [-Connection <SPOnlineConnection>]

Description

Specify a scope as 'Site' to add the custom action to all sites in a site collection.

Examples

------------------EXAMPLE 1------------------

Add-PnPJavaScriptBlock -Name myAction -script '<script>Alert("This is my Script block");</script>' -Sequence 9999 -Scope Site

Add a JavaScript code block to all pages within the current site collection under the name myAction and at order 9999

------------------EXAMPLE 2------------------

Add-PnPJavaScriptBlock -Name myAction -script '<script>Alert("This is my Script block");</script>'

Add a JavaScript code block to all pages within the current web under the name myAction

Parameters

-Connection

Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection.

Type:SPOnlineConnection
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Name

The name of the script block. Can be used to identify the script with other cmdlets or coded solutions

Type:String
Aliases:Key
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Scope

The scope of the script to add to. Either Web or Site, defaults to Web. 'All' is not valid for this command.

Type:CustomActionScope
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Script

The javascript block to add to the specified scope

Type:String
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Sequence

A sequence number that defines the order on the page

Type:Int
Position:Named
Accept pipeline input:False
Accept wildcard characters:False
-Web

This parameter allows you to optionally apply the cmdlet action to a subweb within the current web. In most situations this parameter is not required and you can connect to the subweb using Connect-PnPOnline instead. Specify the GUID, server relative url (i.e. /sites/team1) or web instance of the web to apply the command to. Omit this parameter to use the current web.

Type:WebPipeBind
Position:Named
Accept pipeline input:False
Accept wildcard characters:False