Modern SharePoint Online Programming - Chapter 9

Introduction 

 
Hi guys, let's explore a PS Programming way to create a Modern Team Site collection and associate to a Hub Site collection [HubA].
 
# Connect to SharePoint Online
# This command will prompt the sign-in UI to authenticate
$Tenantadminurl = "https://<TenantName>-admin.sharepoint.com/"
Connect-PnPOnline $Tenantadminurl -useweblogin
$Hubsite="https://<TenantName>.sharepoint.com/sites/HubA"
# Create the new "modern" Team site with below variables as properties
$title = "Custom ModernTeamsiteD"
$url = "https://<TenantName>.sharepoint.com/sites/TeamsiteD"
$teamSiteUrl = New-PnPTenantSite -Url $url -Title $title -Template STS#3 -Owner $owner -TimeZone 10 -Lcid 1033
# Connect to the modern Team site using PnP PowerShell SP cmdlets
# Since we are connecting now to SP side, credentials will be asked
Connect-PnPOnline $teamSiteUrl
# 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
#Associate to Hub site using SPOnline PowerShell
$cred = [System.Net.CredentialCache]::DefaultCredentials
[System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred
Connect-sposervice $Tenantadminurl
Add-SPOHubSiteAssociation $url -HubSite $Hubsite