0

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).

0

You need create a site collection "https://dev.domain.com/sites/admin" first.

Then run the PowerShell below.

$siteColUrl = "https://dev.domain.com/sites/admin"

$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

Then prepare the web application(s) to enable the CreateSite CSOM method using PowerShell below.

$WebApplicationUrl="https://dev.domain.com"
$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"
}    

$webapp=Get-SPWebApplication $WebApplicationUrl
$newProxyLibrary = New-Object "Microsoft.SharePoint.Administration.SPClientCallableProxyLibrary"
$newProxyLibrary.AssemblyName = "Microsoft.Online.SharePoint.Dedicated.TenantAdmin.ServerStub, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
$newProxyLibrary.SupportAppAuthentication = $true
$webapp.ClientCallableSettings.ProxyLibraries.Add($newProxyLibrary)
$webapp.SelfServiceSiteCreationEnabled=$true
$webapp.Update()
Write-Host "Successfully added TenantAdmin ServerStub to ClientCallableProxyLibrary for web application" $WebApplicationUrl
# Reset the memory of the web application
Write-Host "IISReset..."    
Restart-Service W3SVC,WAS -force
Write-Host "IISReset complete on this server, remember other servers in farm as well."

Refer to: PowerShell to enable site collection creation with CSOM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.