iTranslated by AI
Occasional Failures When Updating a Site Immediately After New-SPOSite
When using the SharePoint Online Management Shell to execute New-SPOSite to create a site collection, you may occasionally encounter errors when attempting subsequent update operations (such as creating site groups) via CSOM or other methods.
In the first place, operating on site collections in SharePoint Online takes time. It depends entirely on timing, but if you are unlucky, it can take more than 30 minutes. The SharePoint Online Management Shell periodically polls the status until the operation is complete. Note that you can specify -NoWait if you do not need to wait for the operation to finish.
Sample code for using CSOM is also provided here:
However, in practice, this is sometimes insufficient. Even when a result is returned indicating that the operation is complete, the internal status of the site collection may not yet be "Active." Therefore, if you wish to perform subsequent operations after New-SPOSite, you need to wait further until the status becomes "Active."
$url = "{{site-url}}"
$title = "{{site-title}}"
$owner = "{{site-owner}}"
New-SPOSite -Url $url -Title $title -Owner $owner -StorageQuota 26214400 -LocaleId 1041
while ($true) {
Start-Sleep -Seconds 5
if ((Get-SPOSite -Identity $url).Status -eq "Active") {
break
}
}
Discussion