Permissions to delete Site Collection using CSOM

%3CLINGO-SUB%20id%3D%22lingo-sub-74629%22%20slang%3D%22en-US%22%3EPermissions%20to%20delete%20Site%20Collection%20using%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-74629%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eaccording%20to%20this%20post%2C%20there%20is%20a%20method%20to%20delete%20site%20collections%20using%20csom%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fvesku%2F2015%2F12%2F04%2Fsharepoint-tenant-csom-object-support-in-sharepoint-2013-and-2016%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fblogs.msdn.microsoft.com%2Fvesku%2F2015%2F12%2F04%2Fsharepoint-tenant-csom-object-support-in-sharepoint-2013-and-2016%2F%3C%2FA%3E%3C%2FP%3E%3CP%3EBelow%20the%20methods%20it%20says%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3ENotice%20also%20that%20some%20of%20the%20supported%20methods%20do%20require%20%3CSTRONG%3Especific%20permissions%3C%2FSTRONG%3E%20for%20the%20account%20used%20for%20the%20operations%2C%20if%20you%20do%20not%20use%20oAuth%20for%20granting%20the%20needed%20permissions%20in%20your%20on-premises%20deployment.%20This%20applies%20specifically%20%3CSTRONG%3Efor%20the%20site%20collection%20remove%3C%2FSTRONG%3E%20and%20restore%20operations%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20any%20documentation%20what%20the%20specific%20permissions%20are%3F%20We%20are%20trying%20to%20delete%20site%20collection%20in%20SharePoint%202016%20On%20Prem%20and%20are%20getting%20an%20%22Access%20Denied%22%20error.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-74629%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-77008%22%20slang%3D%22en-US%22%3ERe%3A%20Permissions%20to%20delete%20Site%20Collection%20using%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-77008%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Sorry%2C%20for%20my%20late%20answer.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20are%20correct%3A%20We%20are%20trying%20to%20delete%20Site%20Collection%20on%20Prem%20using%20CSOM.%3C%2FP%3E%3CP%3EWe%20use%20the%20PnP%20Partner%20Pack%20with%20SP2016%20and%20try%20to%20avoid%20any%20server%20side%20code.%20To%20cover%20the%20full%20life%20cycle%20of%20a%20project%20room%2C%20it%20shall%20be%20deleted%20in%20the%20end.%20For%20various%20reasons%20we%20can't%20use%20the%20site%20policy%20feature%20to%20achieve%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20blog%20post%20that%20I%20linked%20it%20is%20explained%2C%20which%20functions%20are%20available%20on%20Premise%20when%20you%20use%20the%20Tenant%20API%20with%20SP2013%20(and%202016).%20It%20is%20said%20that%20the%20method%20to%20delete%20site%20collections%20is%20supported.%20And%20in%20fact%20we%20can%20call%20the%20method%20on%20prem%20but%20we%20always%20get%20an%20access%20denied%20even%20though%20the%20account%20is%20site%20collection%20admin%20in%20the%20tenant%20site%2C%20the%20site%20that%20shall%20be%20deleted.%20We%20even%20tried%20farm-admin%20and%20App-Only-Auth%2C%20but%20nothing%20worked%20for%20us.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECurrently%20I%20believe%20that%20the%20method%20to%20delete%20site%20collections%20in%20CSOM%20is%20available%20but%20the%20needed%20permission%20level%20is%20not%20available%20on%20Prem.%20Can%20anyone%20confirm%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-74700%22%20slang%3D%22en-US%22%3ERe%3A%20Permissions%20to%20delete%20Site%20Collection%20using%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-74700%22%20slang%3D%22en-US%22%3ETo%20answer%20you%20question%3A%20you%20will%20need%20at%20least%20to%20be%20SPO%20Admin%20to%20be%20able%20to%20delete%20the%20site%20collections%20using%20the%20tenant%20object...last%20part%20of%20your%20question%20is%20confusing%3A%20are%20you%20trying%20to%20delete%20OnPremises%20site%20collections%20using%20the%20tenant%20object%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-74639%22%20slang%3D%22en-US%22%3ERe%3A%20Permissions%20to%20delete%20Site%20Collection%20using%20CSOM%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-74639%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20indeed%20is.%20I%20just%20checked%20in%20PnP-PowerShell%20and%20next%20to%20New-PnPTenantSite%20there%20is%20also%20a%20Remove-PnPTenantSite%20whcih%20removes%20a%20site%20collection%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELooking%20at%20the%20code%20in%20use%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%20if%20(!Url.ToLower().StartsWith(%22https%3A%2F%2F%22)%20%26amp%3B%26amp%3B%20!Url.ToLower().StartsWith(%22http%3A%2F%2F%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Uri%20uri%20%3D%20BaseUri%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Url%20%3D%20%24%22%7Buri.ToString().TrimEnd('%2F')%7D%2F%7BUrl.TrimStart('%2F')%7D%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(Force%20%7C%7C%20ShouldContinue(string.Format(Resources.RemoveSiteCollection0%2C%20Url)%2C%20Resources.Confirm))%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Func%26lt%3BTenantOperationMessage%2C%20bool%26gt%3B%20timeoutFunction%20%3D%20TimeoutFunction%3B%0A%0A%23pragma%20warning%20disable%20618%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(!FromRecycleBin)%0A%23pragma%20warning%20restore%20618%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Tenant.DeleteSiteCollection(Url%2C%20!MyInvocation.BoundParameters.ContainsKey(%22SkipRecycleBin%22)%2C%20timeoutFunction)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20else%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Tenant.DeleteSiteCollectionFromRecycleBin(Url%2C%20true%2C%20timeoutFunction)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%3C%2FPRE%3E%3CP%3ETenant%20is%20part%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmicrosoft.online.sharepoint.tenantadministration.tenant.aspx%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EMicrosoft.Online.SharePoint.TenantAdministration%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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

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.

3 Replies
Highlighted

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

Highlighted
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?
Highlighted

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?