Office 365 & PNP PowerShell 2013 : Branding

The PNP branding section you can create custom action like link in the ribbon and other locations as well. For that you need to understand the Ribbon XML.

You can check the following links to know about the ribbon xml. 

  1. Adding a Button to the Server Ribbon`
  2. Add a custom ribbon to your sharepoint site
Now let’s do some practical work. To create the ribbon with PNP powershell, I am going to use the Add‑PnPCustomAction.

To get the all custom actions you need to use the Get‑PnPCustomAction command.

And to remove the custom action we get use the above method to get the all the custom action and delete all the custom action just loop over the collection use the Remove‑PnPCustomAction

In this example, I am going to use the CSV file to read the information and create the Ribbon based on the configuration.

Here is the CSV files for both operation are identical only one different in Action column ‘Del’ and ‘Add’ for distinguish the operation.

The code for cover the above mentioned custom ribbon example. The csv files for as name suggest "BrandingConfig_Add.csv"  for add action and "BrandingConfig_Del.csv" for get the collection and based on the title delete the item.

Get and Set the Home Page

With the help of these two method "Get‑PnPHomePage" and "Set‑PnPHomePage" you can get and set the page of your web. 

Imagine in you migration project you have various site URL and you need to identify the home page of 100 sites this method very handy and you quickly find the home page. 

Also you can write the quick utility to generate the report in the CSV file and vise versa you have 100 site in SharePoint and you need to set the home page. 

You can quickly write the script. here is the Utility. 

Working with JavaScript Block and links

So In this branding section PNP provide you give you handy Cmdlets that help you to add the JavaScript links as well as JavaScript block code. 

Here is the below commands that allows you to add and remove the JavaScript Links as well as the code blocks. 

I tried the code that provided in the example documentation. When I used the same code its not work either at my end. Here is the result of this code.

you can use the "Get‑PnPJavaScriptLink" for return the both script block ("Add‑PnPJavaScriptBlock") and script links "Add‑PnPJavaScriptLink". 

I tried both methods to add the "script block" and link to inject the custom script. In this example I am just give you example how we can add the script block. I faced issue while working with this.

I tried the example mentioned on the documentation, I got the below mentioned result. we do not include the script tag as well as we need to create one variable and assign this alert to this variable. 
Add-PnPJavaScriptBlock -Name myAction -script '<script>Alert("This is my Script block");</script>' -Sequence 9999 -Scope Site

Here is the Output of the. It break the other JavaScript as well. 

So here is the workaround. I check this in my system as well. This working fine as expected.

To remove the Links we can use the Remove-PNPJavaScriptLink method as mentioned in the screenshot.

So here is the full git hub gist. Just need to put the reference of your DLL and do the needful. 


Working with master pages 

So to set and the master page for your site/portal. In PnP cmdlets there are two command that going to help you to set the custom master page and default master page of your site. 

The cmdlets  "Get‑PnPMasterPage" and "Set‑PnPMasterPagepretty easy and very straightforward. I am not going to deep dive into this chapter in more details you can go through the documentation. 

Get-PnPMasterPage [-Web <WebPipeBind>]

PS:> Set-PnPMasterPage -MasterPageServerRelativeUrl /sites/projects/_catalogs/masterpage/oslo.master

PS:> Set-PnPMasterPage -MasterPageServerRelativeUrl /sites/projects/_catalogs/masterpage/oslo.master -CustomMasterPageServerRelativeUrl /sites/projects/_catalogs/masterpage/oslo.master

Enable/Disable the Minimal download strategy 

This cmdlets allows you to enable/disable the minimal download strategy for your current site collection "Set‑PnPMinimalDownloadStrategy"

PS:> Set-PnPMinimalDownloadStrategy -Off

PS:> Set-PnPMinimalDownloadStrategy -On


Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

STS CryptographicException Error : Key set does not exist

Query suggestions in SP 2013 Using Rest API (/_api/search/suggest)