Office 365 & PNP PowerShell 2013 : Branding Part1

Last post we have learned about the other branding topics as mentioned below. 

1. Create the bulk custom Actions using CSV files. 
2. Set the Home page URL using CSV file. 
3. Add and remove the script blocks and script links. 

Now this post we will learn how we can create the bulk links using "Add‑PnPNavigationNode" method. So in this example I am going to create the utility that help you to create the multiple links in the single go. For this we will be using the csv files for configure every thing. As you know using this method you can add the links to following locations. 



1. TopNavigatoin



 2. QuickLunch

 3. SearchNav


So here is the solution without taking your much of time. 
#Dev Import
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
function CreateNavigation ($csvPath ,$siteUrl){
#get and save your O365 credentials
#connect to the root site collection first
Connect-PnPOnline –Url $siteUrl -CurrentCredentials
$message = "Connected to site : $siteUrl"
$message
Write-Host $message -ForegroundColor Green
$MyFile = Import-Csv $csvPath
# Looping the csv file collection
foreach ($myRow in $MyFile)
{
$NewURL = $($myRow.SiteURL)
$External=[System.Convert]::ToBoolean($myRow.External)
$First=[System.Convert]::ToBoolean($myRow.First)
try
{
$full = ($siteUrl)+ "/"+($myRow.Url);
if($myRow.Header -eq ""){
Add-PnPNavigationNode -Title $($myRow.Title) -Url $full -Location $($myRow.Location) -External:$External -First:$First
}else{
Add-PnPNavigationNode -Title $($myRow.Title) -Url $full -Location $($myRow.Location) -Header $($myRow.Header) -External:$External -First:$First
}
$message = "Navigation Created : $($myRow.Title) and URL :$($siteUrl)/$($NewURL)for location $($myRow.Location)"
$message
Write-Host $message -ForegroundColor Green
}
catch
{
$message = "Unable to Create Navigation for Title: $($myRow.Title) and URL :$($siteUrl)/$($NewURL) for location $($myRow.Location)"
$message
Write-Host $message -ForegroundColor Red
"$($_.Exception.Message)"
}
}
}
$siteUrl="http://myintranet.com/sites"
$path='C:\Users\basantp\Documents\PNP Blog Section\Code\Branding'
$inputFile =$path + "\CreateNavigation.csv"
CreateNavigation $inputFile $siteUrl
Location Title Header Url External First
TopNavigationBar Top Top TRUE TRUE
TopNavigationBar Child 1 Top Child1 TRUE TRUE
TopNavigationBar Child 2 Top Child2 TRUE TRUE
TopNavigationBar Child 3 Top Child3 TRUE TRUE
TopNavigationBar Child 4 Top Child4 TRUE TRUE
QuickLaunch Left Nav Left TRUE TRUE
QuickLaunch Child Left Nav1 Left Nav ChildLeft1 TRUE TRUE
QuickLaunch Child Left Nav2 Left Nav ChildLeft2 TRUE TRUE
QuickLaunch Child Left Nav3 Left Nav ChildLeft3 TRUE TRUE
QuickLaunch Child Left Nav4 Left Nav ChildLeft4 TRUE TRUE
QuickLaunch Child Left Nav5 Left Nav ChildLeft5 TRUE TRUE
SearchNav SearchNav1 SearchNav1 TRUE TRUE
SearchNav SearchNav2 SearchNav2 TRUE TRUE


Remove the Navigation using "Remove‑PnPNavigationNode"
We have learned how to add the navigation, now the question come if we need to delete the same above created structured. 

So friends, I am facing very taught time to make this possible. So I am not able to delete the links when there are parent child relationship the same as we have in the above example. 

So this example working fine. 

Add-PnPNavigationNode -Title "hello" -Url "http://test-dev.com/sites/test1" -Location QuickLaunch -External:$true -First:$true

Add-PnPNavigationNode -Title "hello1" -Url " http://test-dev.com/sites/test1" -Header "hello" -Location QuickLaunch -External:$true -First:$true


To Remove the links 

Remove-PnPNavigationNode -Title "hello" -Header "hello1" -Location QuickLaunch -Force -ErrorAction Stop #This will remove only the "Hello"

Remove-PnPNavigationNode -Title "hello" -Location QuickLaunch -Force -ErrorAction Stop #This will remove the both "hello" and child "hello1" 



So I tired and created the same csv solution as well. The most common error encounter many time. 

"Sequence contains more than one matching element"

So here is the solution, if you can fix this issue please share your comments with me. 


#Dev Import
Import-Module 'C:\Users\basantp\Documents\PNP Blog Section\Code\SharePointPnPPowerShell2013\SharePointPnP.PowerShell.2013.Commands.dll';
function Remove-Navigation ($csvPath , $siteUrl) {
#get and save your O365 credentials
#connect to the root site collection first
Connect-PnPOnline –Url $siteUrl -CurrentCredentials
$message = "Connected to site : $siteUrl"
Add-Content $logFileName $message
Write-Host $message -ForegroundColor Green
$MyFile = Import-Csv $csvPath
# Looping the csv file collection
foreach ($myRow in $MyFile) {
foreach ($myRow in $MyFile) {
try {
#Common Error : Sequence contains more than one matching element
if ($myRow.Header -ne "" -and $myRow.Header -ne $null) {
Remove-PnPNavigationNode -Location $($myRow.Location) -Title $($myRow.Title) -Header $($myRow.Header) -Force -ErrorAction Stop
}
else {
Remove-PnPNavigationNode -Location $($myRow.Location) -Title $($myRow.Title) -Force -ErrorAction Stop
}
$message = "Navigation Deleted : $($myRow.Title) and locatoin $($myRow.Location)"
Add-Content $logFileName $message
Write-Host $message -ForegroundColor Green
}
catch {
$message = "Unable to delete the Navigation : $($myRow.Title) and location $($myRow.Location)"
Add-Content $logFileName $message
Write-Host $message -ForegroundColor Red
Add-Content $logFileName "$($_.Exception.Message)"
}
}
}
$siteUrl = "http://myintranet.com/sites"
$path = 'C:\Users\basantp\Documents\PNP Blog Section\Code\Branding'
$inputFile = $path + "\RemoveNavigation.csv"
Remove-Navigation $inputFile $siteUrl
Location Title Header
TopNavigationBar Top
TopNavigationBar Child 1 Top
TopNavigationBar Child 2 Top
TopNavigationBar Child 3 Top
TopNavigationBar Child 4 Top
QuickLaunch Left Nav
QuickLaunch Child Left Nav1 Left Nav
QuickLaunch Child Left Nav2 Left Nav
QuickLaunch Child Left Nav3 Left Nav
QuickLaunch Child Left Nav4 Left Nav
QuickLaunch Child Left Nav5 Left Nav
SearchNav SearchNav1
SearchNav SearchNav2
Working with Responsive UI

To make your SharePoint site responsive for both Microsoft SharePoint 2013/2016 on-premises or SharePoint Online using the PowerShell cmdlet Enable-PnPResponsiveUI, and also provides you the capability to enable a custom Responsive UI for a Site Collection. 

First the solution built externally (link). Now this is the part of the SharePoint PNP Framework. 

The Responsive UI is applied to the following pages of the root site of a Site Collection, as well as of any sub-site (as long as you disable the "Mobile Browser View" feature in any specific sub-site):

  • Home Page
  • Web Part Pages
  • Wiki Pages
  • Document Libraries
  • Lists
  • Site Contents
  • Site Settings
There are two command reponsible for enable and disable the Responsive UI. 

Mobile Responsive views screenshots taken from Github. 



Working with Themes
Get‑PnPTheme and Set‑PnPTheme Cmdlets are set and get the sharepoint theme. 

Frankly speaking I am not big fan of this Theme engine, but you can check this blog post how to create custom themes "http://www.learningsharepoint.com/2013/06/03/create-custom-theme-in-sharepoint-2013-step-by-step-tutorial/". Once you done you can upload it and and set the Theme via Set‑PnPTheme

Comments

Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

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

STS CryptographicException Error : Key set does not exist