Mon. Jan 3rd, 2022
function new-SPOnlineSite ($siteUrl,$title,$siteOwner, $template) 
{
$siteExists = $null;
$siteExistsInRecycleBin = $null;

try
{
#verify if site already exists in SharePoint Online
$siteExists = get-SPOSite $siteUrl;

#verify if site already exists in the recycle bin
$siteExistsInRecycleBin = get-SPODeletedSite $siteUrl;
}
catch
{

}

#create site if it doesn't exists
if (($siteExists -eq $null) -and ($siteExistsInRecycleBin -eq $null)) 
{
write-host "info: Creating $($title)" -foregroundcolor green

if ($template -eq 'CUSTOM')
{
New-SPOSite -Url $siteUrl -title $title -Owner $siteOwner -StorageQuota $storageQuota -NoWait -ResourceQuota $resourceQuota
}
else
{
New-SPOSite -Url $siteUrl -title $title -Owner $siteOwner -StorageQuota $storageQuota -NoWait -ResourceQuota $resourceQuota -Template $template
}

}
elseif ($siteExists -ne $null)
{
write-host -foregroundcolor red "info: $($siteUrl) already exists"
throw;
}
else
{
write-host  -ForegroundColor red"info: $($siteUrl) still exists in the recyclebin" 
throw;
}

}

This website uses cookies. By continuing to use this site, you accept our use of cookies.