We are trying to get Site Collections to be created from CSOM (C#) and are having trouble. Almost all examples of this found on the Internet are for 2013/2016 SharePoint or SharePoint Online.
In order to "allow" CSOM to create Site Collections, we followed a setup that works in 2013/2016 (link: https://blogs.msdn.microsoft.com/vesku/2016/11/24/provisioning-site-collections-with-csom-in-sharepoint-2016/) Unfortunately, it didn't work for us as it seems that something has changed in SharePoint 2019 and no one has identified it (and shared).
TLDR; We need to create Site Collections in SharePoint 2019 on-premise via CSOM/c# application (aka "not" in SharePoint)
For instance, we run this code in SharePoint 2019 Management Console
$siteColUrl = "https://dev.domain.com/sites/admin"
$site = get-spsite -Identity $siteColUrl
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$site = get-spsite -Identity $siteColUrl
$site.AdministrationSiteType = [Microsoft.SharePoint.SPAdministrationSiteType]::TenantAdministration
... and it produces these errors:
get-spsite : Cannot find an SPSite object with Id or Url: https://dev.domain.com/sites/admin.
At line:2 char:9
+ $site = get-spsite -Identity $siteColUrl
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletGetSite:SPCmdletGetSite) [Get-SPSite], SPCmdletPipeBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
get-spsite : Cannot find an SPSite object with Id or Url: https://dev.domain.com/sites/admin.
At line:11 char:9
+ $site = get-spsite -Identity $siteColUrl
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share...SPCmdletGetSite:SPCmdletGetSite) [Get-SPSite], SPCmdletPipeBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetSite
The property 'AdministrationSiteType' cannot be found on this object. Verify that the property exists and can be set.
At line:12 char:1
+ $site.AdministrationSiteType = [Microsoft.SharePoint.SPAdministration ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Also, when we run our C#/CSOM code for the ExecuteQuery command, we get this error:
Cannot find stub for type with id \"{268004ae-ef6b-4e9b-8425-127220d84719}\". The specified server may not support APIs used in this operation
Supposedly, the fix for this is similar to the setup mentioned in the definetenantadminsite.ps1 PowerShell script from the original blog post.
http://sadomovalex.blogspot.com/2015/08/fix-problem-with-missing-api-error-when.html
Unfortunately, it has the same error as above (wasn't expected to work since it was the same code essentially).