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

Create a SharePoint Intranet

Pages - Functions

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 department names are added to a Departments array, which is the basis for most of the code.

The root site is a HQ site that we created in an earlier article. In the articles before this one, we have created Communication subsites, one for each department, we have added a common navigation for all sites and also a link to an external link and we have given the three subsites modern apps for photos and tasks.

In the demo below, Peter creates modern pages for Progress, Problems and Plans for the three department subsites. He adds this code to a forEach loop that runs through a Departments array and creates the common navigation and the apps.

However, first he makes the loop easier tor read by removing the code for apps and navigation and adding it to two new functions. In the forEach loop, he instead adds calls to these two functions.

function Add-Apps(){
    #Add apps
    Create-MyApp -ListName "Photos" -AppType PictureLibrary
    Create-MyApp -ListName "Tasks" -AppType Tasks

function Add-SubsiteNavigation(){
    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


The three new pages are created with the Add-PnPClientSidePage cmdlet, which only requires a value the Name parameter. Peter adds these commands to another function.

function Add-Pages(){
    Add-PnPClientSidePage -Name "Progress"
    Add-PnPClientSidePage -Name "Problems"
    Add-PnPClientSidePage -Name "Plans"

Finally Peter adds a call to the Add-Pages function in the forEach loop.

foreach($Dep in $Departments){
    $CurrWebURL =($URL + "/" + $Dep)
    #Connect to the department site
    Connect-PnPOnline $CurrWebURL 
     PowerShell with SharePoint from Scratch coverAdd-SubsiteNavigation

You will find more detailed explanations in the book.

Download the script that Peter uses in the demo

In the next article, we will add progress messages to the code

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