Forum Discussion

Markus Ihloff's avatar
Markus Ihloff
Copper Contributor
Jun 02, 2017

Permissions to delete Site Collection using CSOM

Hi,

 

according to this post, there is a method to delete site collections using csom:

https://blogs.msdn.microsoft.com/vesku/2015/12/04/sharepoint-tenant-csom-object-support-in-sharepoint-2013-and-2016/

Below the methods it says

 

Notice also that some of the supported methods do require specific permissions for the account used for the operations, if you do not use oAuth for granting the needed permissions in your on-premises deployment. This applies specifically for the site collection remove and restore operations

 

Is there any documentation what the specific permissions are? We are trying to delete site collection in SharePoint 2016 On Prem and are getting an "Access Denied" error.

  • There indeed is. I just checked in PnP-PowerShell and next to New-PnPTenantSite there is also a Remove-PnPTenantSite whcih removes a site collection

     

    Looking at the code in use:

     

     if (!Url.ToLower().StartsWith("https://") && !Url.ToLower().StartsWith("http://"))
                {
                    Uri uri = BaseUri;
                    Url = $"{uri.ToString().TrimEnd('/')}/{Url.TrimStart('/')}";
                }
    
                if (Force || ShouldContinue(string.Format(Resources.RemoveSiteCollection0, Url), Resources.Confirm))
                {
                    Func<TenantOperationMessage, bool> timeoutFunction = TimeoutFunction;
    
    #pragma warning disable 618
                    if (!FromRecycleBin)
    #pragma warning restore 618
                    {
                        
                        Tenant.DeleteSiteCollection(Url, !MyInvocation.BoundParameters.ContainsKey("SkipRecycleBin"), timeoutFunction);
                    }
                    else
                    {
                        Tenant.DeleteSiteCollectionFromRecycleBin(Url, true, timeoutFunction);
                    }
    
                }

    Tenant is part of the Microsoft.Online.SharePoint.TenantAdministration

    • jcgonzalezmartin's avatar
      jcgonzalezmartin
      MVP
      To answer you question: you will need at least to be SPO Admin to be able to delete the site collections using the tenant object...last part of your question is confusing: are you trying to delete OnPremises site collections using the tenant object?
      • Markus Ihloff's avatar
        Markus Ihloff
        Copper Contributor

        Hi Sorry, for my late answer.

         

        You are correct: We are trying to delete Site Collection on Prem using CSOM.

        We use the PnP Partner Pack with SP2016 and try to avoid any server side code. To cover the full life cycle of a project room, it shall be deleted in the end. For various reasons we can't use the site policy feature to achieve this.

         

        In the blog post that I linked it is explained, which functions are available on Premise when you use the Tenant API with SP2013 (and 2016). It is said that the method to delete site collections is supported. And in fact we can call the method on prem but we always get an access denied even though the account is site collection admin in the tenant site, the site that shall be deleted. We even tried farm-admin and App-Only-Auth, but nothing worked for us.

         

        Currently I believe that the method to delete site collections in CSOM is available but the needed permission level is not available on Prem. Can anyone confirm this?

Resources