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

Create a SharePoint Intranet

Apps and External Link Removal

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, and we have added a common navigation for all sites and also a link to an external link.

In earlier demos Peter has also written code that removes the subsites and the navigation, but the external link on the HQ site is not removed by that code. Therefore, Peter starts the demo below with solving that problem. He also adds all the removal code into a function.

function Remove-All(){
    foreach($Dep in $Departments){
        Remove-PnPWeb -Url $Dep -Force
    }
    $AllNodes = Get-PnPNavigationNode -Location QuickLaunch
    foreach($Node in $AllNodes){
        #$Node = $AllNodes[0]
        if($Node.Title -eq "Pedalling"){
            Remove-PnPNavigationNode  -Identity $Node.Id -Force
        }
    }
}

After that Peter creates a Photos Picture library and a Tasks list for each of the department subsites. This is something that should be done in the same process as the subsite navigation links, so in the forEach loop that executes that, Peter adds two calls to the Create-MyApp function that he created in an earlier demo.

foreach($Dep in $Departments){
    $CurrWebURL =($URL + "/" + $Dep)
    #Connect to the department site
    Connect-PnPOnline $CurrWebURL 

    #Add apps
    Create-MyApp -ListName "Photos" -AppType PictureLibrary
    Create-MyApp -ListName "Tasks" -AppType Tasks

    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
}







Download the script that Peter uses in the demo


In the next article, Peter shows how to use the Batch functionality to create an app with items.

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

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved