Create a SharePoint Intranet

Themes

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 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 one Communication subsite for each department, added a common navigation for all sites and also a link to an external link. Moreover, we have given the three subsites modern apps for photos and tasks and pages for progress, problems and plans.

In the previous demo, Peter showed how to add progress messages to the code, so that we can follow the creation process in the PowerShell ISE console pane.

Now it is time to give each subsite a custom theme. Each theme name is the same as the department and subsite name:
  1. Create a theme in Microsoft’s UI Fabric Theme Designer at https://fabricweb.z5.web.core.windows.net/pr-deploy-site/refs/heads/master/theming-designer/index.html.
  2. Paste the code generated in the UI Fabric Theme Designer into a new PowerShell function with a variable that stores the code for the theme.
  3. Repeat these steps so that the function contains variables and theme code for all subsites.
  4. Add the themes to the tenant with the cmdlet Add-PnPTenantTheme.
    function Add-Themes(){
        $SalesTheme = @{...}
        Add-PnPTenantTheme -Identity "Sales" -Palette $SalesTheme -IsInverted $false
        $SupportTheme = @{...}
        Add-PnPTenantTheme -Identity "Support" -Palette $SupportTheme -IsInverted $false
        $ProductionTheme = @{...}
        Add-PnPTenantTheme -Identity "Production" -Palette $ProductionTheme -IsInverted $false
        Write-Host "Themes added" -ForegroundColor Green
    }
  5. Add the themes to the subsites with the cmdlet Set-PnPWebTheme.
    foreach($Dep in $Departments){
        $CurrWebURL =($URL + "/" + $Dep)
        #Connect to the department site
        Write-Host ("Fixing " + $CurrWebURL  + " ... ") -ForegroundColor Yellow
        Connect-PnPOnline $CurrWebURL 
        Add-Apps
        Add-SubsiteNavigation
        Add-Pages
        Set-PnPWebTheme -Theme $Dep
        Write-Host ("Done with " + $CurrWebURL ) -ForegroundColor Green
    }
  6. Add the Remove-PnPTenantTheme cmdlet to the Remove-All function.
    function Remove-All(){
        Connect-PnPOnline $URL 
        foreach($Dep in $Departments){
            Write-Host ("Removing subsite " + $Dep + " ... ") -ForegroundColor Red
            Remove-PnPWeb -Url $Dep -Force
            Remove-PnPTenantTheme -Identity $Dep
        }
        $AllNodes = Get-PnPNavigationNode -Location QuickLaunch
        foreach($Node in $AllNodes){
            #$Node = $AllNodes[0]
            if($Node.Title -eq "Pedalling"){
                Remove-PnPNavigationNode  -Identity $Node.Id -Force
            }
        }
        Write-Host ("Everything removed") -ForegroundColor Green
    }

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

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved