Home >Tips >PowerShell with SharePoint from Scratch >Create intranet - navigation kalmstrom.com site map icon Site map  

Create a SharePoint Intranet

Navigation

A PowerShell with SharePoint tutorial

PowerShell icon
As a last part in our series PowerShell with SharePoint from Scratch, we offer some articles and demos where Peter Kalmström explains how to create an intranet with three subsites for three departments in a small company.

The root site is a HQ site that we created in an earlier article. In the previous article, we created subsites, one for each department. All sites are Communication sites, and this site type has no global navigation. Instead, the Quick launch is placed on top of the page.

In the demo below, Peter shows how to write a PowerShell script that gives the sites a common navigation, so that all sites can be reached from any other site. All sites will also have an external link.

The navigation code is written in three steps. The two forEach loops both get data from the array of departments that we created in the previous article.

Subsite links on the root site

In the forEach loop created in the previous article, Peter comments out the create subsite command and adds a command with the Add-PnPNavigationNode cnmdlet that adds the links to the subsites on the HQ site.

Add-PnPNavigationNode -Location QuickLaunch -Title $Dep -Url ($URL + "/" + $Dep)

Links on the subsites

Peter creates a new forEach loop for the subsites and starts the execution with connecting to the current subsite.

An encapsulated forEach loop runs an Add-PnPNavigationNode command if the current department name is not equal to the current subsite name, to add the links between the subsites.

Two other Add-PnPNavigationNode commands add links to the HQ site and the external site.

foreach($Dep in $Departments){
    $CurrWebURL =($URL + "/" + $Dep)
    Connect-PnPOnline $CurrWebURL 
    foreach($DepSub in $Departments){
        if($Dep -ne $DepSub){
            Add-PnPNavigationNode -Location QuickLaunch -Title $DepSub -Url ($URL + "/" + $DepSub)
        }
    }
    Add-PnPNavigationNode -Location QuickLaunch -Title "HQ" -Url $URL
    Add-PnPNavigationNode -Location QuickLaunch -Title "Pedalling" -Url "https://pedalling.com" -External
}

External link on the root site

Peter connects back to the HQ site and creates the external link with another Add-PnPNavigationNode command.

Connect-PnPOnline $URL 
Add-PnPNavigationNode -Location QuickLaunch -Title "Pedalling" -Url "https://pedalling.com" -External





Download the script that Peter uses in the demo


In the next article, we add apps to the subsites and create removal code for all navigation.






Follow kalmstrom.com on LinkedIn Facebook or Twitter!

back icon next icon
Products Buy FAQ Services Tips Books Contact About Us Tools

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved