All scripts
Microsoft 365 388

Provision a New SharePoint Communication Site

A PnP.PowerShell script that spins up a new SharePoint communication site, sets the right sharing level, and adds an owner in one run instead of clicking through the admin center each time.

New-SharePointCommunicationSite.ps1
<#
.SYNOPSIS
    Creates a new SharePoint Online communication site with standard sharing and owner settings.

.DESCRIPTION
    Connects to SharePoint Online using PnP.PowerShell, creates a new communication site,
    sets external sharing based on how sensitive the site is, adds a site collection admin,
    and applies a starting theme. Meant to replace the usual click through in the admin
    center when you are standing up sites for different teams or projects on a regular basis.

.PARAMETER SiteUrl
    Full URL for the new site, for example https://contoso.sharepoint.com/sites/finance-2026.

.PARAMETER SiteTitle
    Display title for the site.

.PARAMETER OwnerUpn
    UPN of the person who should be added as a site collection admin.

.PARAMETER TenantAdminUrl
    URL of your SharePoint admin center, for example https://contoso-admin.sharepoint.com.

.PARAMETER SharingLevel
    Standard or Sensitive. Sensitive restricts external sharing to existing guests only.

.EXAMPLE
    .\New-SharePointCommunicationSite.ps1 -SiteUrl "https://contoso.sharepoint.com/sites/finance-2026" -SiteTitle "Finance 2026" -OwnerUpn "dana@contoso.com" -TenantAdminUrl "https://contoso-admin.sharepoint.com"

.AUTHOR
    Shehryar Hassan
#>

[CmdletBinding()]
param(
    [Parameter(Mandatory = $true)]
    [string]$SiteUrl,

    [Parameter(Mandatory = $true)]
    [string]$SiteTitle,

    [Parameter(Mandatory = $true)]
    [string]$OwnerUpn,

    [Parameter(Mandatory = $true)]
    [string]$TenantAdminUrl,

    [ValidateSet("Standard", "Sensitive")]
    [string]$SharingLevel = "Standard"
)

if (-not (Get-Module -ListAvailable -Name PnP.PowerShell)) {
    Write-Error "PnP.PowerShell module is not installed. Run: Install-Module PnP.PowerShell -Scope CurrentUser"
    exit 1
}

Import-Module PnP.PowerShell -ErrorAction Stop

Write-Host "Connecting to $TenantAdminUrl ..."
Connect-PnPOnline -Url $TenantAdminUrl -Interactive

Write-Host "Creating communication site at $SiteUrl ..."
New-PnPSite -Type CommunicationSite -Title $SiteTitle -Url $SiteUrl -Wait -ErrorAction Stop

Write-Host "Connecting to the new site to apply settings ..."
Connect-PnPOnline -Url $SiteUrl -Interactive

Write-Host "Adding $OwnerUpn as a site collection admin ..."
Add-PnPSiteCollectionAdmin -Owners $OwnerUpn

if ($SharingLevel -eq "Sensitive") {
    Write-Host "Restricting external sharing to existing guests only ..."
    Set-PnPTenantSite -Url $SiteUrl -SharingCapability ExistingExternalUserSharingOnly
} else {
    Write-Host "Setting external sharing to the tenant default ..."
    Set-PnPTenantSite -Url $SiteUrl -SharingCapability ExternalUserAndGuestSharing
}

Write-Host "Applying a starting theme ..."
try {
    Set-PnPWebTheme -Theme "Blue" -ErrorAction Stop
} catch {
    Write-Warning "Could not apply a theme automatically, this can be set later from site settings."
}

Write-Host "Done. New site is ready at $SiteUrl"

Disconnect-PnPOnline

Read it before you run it, and test in a safe tenant first.