Modern SharePoint Online Programming - Chapter 4

Introduction 

 
Hi guys, let's explore a way to create a Modern Communication site and associate it to a Hub site using the below PS commands.
 
# Connect to SharePoint Online
# This command will prompt the sign-in UI to authenticate
$Tenantadminurl = "https://<TenantName>-admin.sharepoint.com/"
$Hubsite="https://<TenantName>.sharepoint.com/sites/HubB"
Connect-PnPOnline $Tenantadminurl -useweblogin
# Create the new "modern" communication site with SiteDesign Topic/Showcase/Blank
$communicationSiteUrl = New-PnPSite -Type CommunicationSite -Title "TestCommD" -Url "https://bunnomatic1.sharepoint.com/sites/TestCommD" -Description "Test CommD Blank Type Creation" -Classification "CommD" -SiteDesign Blank
# Connect to the modern site using PnP PowerShell SP cmdlets
# Since we are connecting now to SP side, credentials will be asked
Connect-pnponline -url $communicationSiteUrl -useweblogin
# Now we have access on the SharePoint site for any operations
$context = Get-PnPContext
$web = Get-PnPWeb
#$context.Load($web, $web.Title)
#Execute-PnPQuery
$web.Title
#Applying SiteFooter
Apply-PnPProvisioningTemplate -Path D:\SiteFooter1.xml
#Associate to Hub site using SPOnline PowerShell
$cred = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred
Connect-sposervice $Tenantadminurl
Add-SPOHubSiteAssociation $communicationSiteUrl -HubSite $Hubsite
 
For Site Footer, please refer the below code and place it in your local path and mention it the same as above, applying the SiteFooter PS cmdlet.
<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2019/03/ProvisioningSchema">
<pnp:Preferences Generator="OfficeDevPnP.Core, Version=3.10.1906.0, Culture=neutral, PublicKeyToken=null" />
<pnp:Templates ID="CONTAINER-TEMPLATE-349B964A1A644BA3A310BFA16668495E">
<pnp:ProvisioningTemplate ID="TEMPLATE-349B964A1A644BA3A310BFA16668495E" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite">
<pnp:Footer Enabled="true" RemoveExistingNodes="true">
<pnp:FooterLinks>
<pnp:FooterLink DisplayName="Contact Us" Url="mailto:[email protected]" />

<pnp:FooterLink DisplayName="IT Support" Url="http://ClientName.zendesk.com" />
<pnp:FooterLink DisplayName="Help" Url="https://<TenantName>.sharepoint.com/sites/Client/SitePages/Client-Hubs-Help-Page.aspx" />

</pnp:FooterLinks>
</pnp:Footer>
</pnp:ProvisioningTemplate>
</pnp:Templates>
</pnp:Provisioning>
 
Above, the  Site Footer code has 3 Footer links, and needs to be added in the reverse order to show it's affected from left to right on your Site collection page.
 
You can add more links, but the order that gets reflected is Bottom to Top on your Site Footer and Left to Right Alignment. Make sure that you take the necessary precautions with it.