Create a SharePoint Intranet


A PowerShell with SharePoint tutorial

PowerShell icon
The is the last article in our Tips series on PowerShell with SharePoint, which is finished by som articles on how to create an intranet with 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 Communication site, and in several articles before this one, Peter Kalmström has shown how to create one subsite for each department and add a common navigation for all sites. He has also given the three subsites modern apps for photos and tasks and pages for progress, problems and plans, and each one has its own theme.

The code for all this has become rather long, so Peter has added progress messages so that we can follow the creation process in the PowerShell ISE console pane.

Now Peter will add a video to a Content Embed web part on the homepage of the Sales subsite. He will use the cmdlet Add-PnPClientSideWebPart, which adds a client-side (modern) web part to an existing client-side page.

The modern SharePoint Content Embed web part requires that the value of the WebPartProperties parameter is given as a Json string, because its settings are stored and set via a Json property on the web part. Therefore, we must build a Json string from the YouTube embed code to use it in PowerShell.

Connect-PnPOnline ($URL + "/Sales/")
#Building json string
#Change here for another video
$YouTubeVideoEmbedCode = '<iframe width="560" height="315" src="" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'

Class WebPartProperties{

$YTVideoProps = New-Object WebPartProperties
$YTVideoProps.embedCode = $YouTubeVideoEmbedCode 

[string] $WebpartPropsJson = (ConvertTo-Json $YTVideoProps)
#End building json string
Add-PnPClientSideWebPart -Page "Home"  PowerShell with SharePoint from Scratch cover-DefaultWebPartType ContentEmbed -WebPartProperties $WebpartPropsJson

You will find more detailed explanations in the book.

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

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved