Question

# 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 :)

Était-ce utile?

La solution

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.

Autres conseils

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..."
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top