New-PnPSite - Check if site is allready created?
-
08-02-2021 - |
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 :)
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:
OTHER TIPS
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..."
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange