Create a SharePoint Intranet
Pages - Functions
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, 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-PnPPage cmdlet,
which only requires a value the Name parameter. Peter adds
these commands to another function.
function Add-Pages(){
Add-PnPPage -Name "Progress"
Add-PnPPage
-Name "Problems"
Add-PnPPage
-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
Add-Apps
Add-SubsiteNavigation
Add-Pages
}
Note: In the demo, Peter uses another cmdlet for page creation.
This cmdlet has now be replaced by the cmdlet Add-PnPPage.
|