0
# CREATE COMMUNICATION SITE
New-PnPSite `
  -Type CommunicationSite `
  -Title $team `
  -Url ("https://hiddenforsecurity.sharepoint.com/sites/" + $team) `
  -SiteDesign 'Blank' 

I need to wrap this in a if statement that will check if the site is already created, can anybody point me in the right direction?

TY :)

4

2 Answers 2

1

Use something like below:

$site = Get-SPOWeb -Identity "Site" -ErrorAction SilentlyContinue
if ($subsite -eq $null) {
  Write-Host "Site does not exist, create..." -ForegroundColor Yellow
}
else {
  Write-Host "Subsite already exist" -ForegroundColor Green
}

Reference:

SharePoint Online: Site Operation with PnP Powershell.

4

You can use the Get-PnPTenantSite command to check if a site collection exists or not as below:

$site = ""
Try
{
    Write-Host "Checking, if site already exists..."

    $site = Get-PnPTenantSite -Url "<your-site-url>" -ErrorAction SilentlyContinue
}
Catch
{    
}

if ($site -ne $null)
{
    Write-Host "Site already exists, use existing..."
}
else
{
    Write-Host "Site doesn't exist, creating new..."
}
1
  • Thx! I was trying to use Get-PNPSite and Get-PNPWeb with no luck. Commented Jan 29, 2020 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.