Create a SharePoint Intranet
Apps and External Link Removal
A PowerShell with SharePoint tutorial
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
}
|