I'm implementing some PowerShell scripts for helping my team create new SharePoint Online sites. One of these scripts follows these requirements:
- be able to create a site,
- be able to remove the site if previously exists,
- be able to return the site created
Seems to be easy using the SharePoint Online Management Shell and that's it but I'm facing an issue that throws the following error:
Get-SPOSite : Error in proc_GetSitesAllowDenyList, no rowset returned.
I get it sometimes, not always, but don't know why and don't find any explanation about it googling. Let me share my code and try to explain it:
# Obtains the site if exists
$Instance = Get-SPOSite $Url
# Removes the site in case that exists and user requires
If($null -ne $Instance -and $true -eq $RemoveIfExists) {
Write-Host "Removing site "$Url"..."
Remove-SPOSite $Url -Confirm:$false
Remove-SPODeletedSite $Url -Confirm:$false
$Instance = $null
}
# Creates the site if not exists
If($null -eq $Instance) {
Write-Host "Creating site "$Url"..."
$Instance = New-SPOSite -Owner $Owner -Url $Url -Title $Title -StorageQuota $Quota -Template $Template
}
# Returns the site
Get-SPOSite $Url
As I said, seems that everything runs perfectly fine but when reaching the last line throws the error. Do you think that I need to add some delay to let SharePoint/Office 365 completely do all the stuff need before retrieving the site?