Add Modern Team Subsites to a SharePoint Online Site (SharePoint PnP)

Let’s say you want to create a batch of modern team sites, especially if you want to do this many times over for different locations, here is an easy script I put together which will accomplish it in a few moments.

$encpassword = convertto-securestring -String <password> -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist <logonid>, $encpassword

Connect-PnPOnline "https://contoso.sharepoint.com/corporate" -Credentials $cred

New-PnPWeb -Title "Accounting" -Url accounting -Template "STS#3"
New-PnPWeb -Title "Customer Service" -Url customerservice -Template "STS#3"
New-PnPWeb -Title "Executive" -Url executive -Template "STS#3"
New-PnPWeb -Title "Finance" -Url finance -Template "STS#3"
New-PnPWeb -Title "HR" -Url hr -Template "STS#3"
New-PnPWeb -Title "IT" -Url it -Template "STS#3"
New-PnPWeb -Title "Legal" -Url legal -Template "STS#3"
New-PnPWeb -Title "Shipping" -Url shipping -Template "STS#3"

//handle the navigation updates

//leave a link in place on the quick launch
ForEach ($item In Get-PnPNavigationNode) {if ($item.Title -notlike "<leavesomelink>*") { Remove-PnPNavigationNode -Identity $item.Id -Force}}

//add new subsites to the quick launch
$url = (get-pnpweb).serverrelativeurl + "/accounting"
Add-PnPNavigationNode -Location QuickLaunch -Title "Accounting" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/customerservice"
Add-PnPNavigationNode -Location QuickLaunch -Title "Customer Service" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/executiveteam"
Add-PnPNavigationNode -Location QuickLaunch -Title "Executive Team" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/finance"
Add-PnPNavigationNode -Location QuickLaunch -Title "Finance" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/hr"
Add-PnPNavigationNode -Location QuickLaunch -Title "HR" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/it"
Add-PnPNavigationNode -Location QuickLaunch -Title "IT" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/legal"
Add-PnPNavigationNode -Location QuickLaunch -Title "Legal" -Url $url
$url = (get-pnpweb).serverrelativeurl + "/shipping"
Add-PnPNavigationNode -Location QuickLaunch -Title "Shipping" -Url $url

 
The only downsides to this is that you still (may posssibly) need to go in and set up the permissions after the sites are created, as it will create them using inherited permissions.