0

I have a requirement on SharePoint Online Office 365. As per my requirement, I have to delete all the Site Collection from SharePoint Online Office 365 Admin Center using pnp csom programmatically.

Anyone can suggest that how can I delete all the Site Collection?

2 Answers2

1

You can use DeleteSiteCollection extension method to remove the site collection.

It can be used as below:

string userName = "admin@tenant.onmicrosoft.com";
string password = "password";

string siteUrl = "https://tenant-admin.sharepoint.com/";

using (ClientContext clientContext = new ClientContext(siteUrl))
{
    SecureString securePassword = new SecureString();
    foreach (char c in password.ToCharArray())
    {
        securePassword.AppendChar(c);
    }

    clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
    clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);

    var tenant = new Tenant(clientContext);

    // use false, if you want to keep site collection in recycle bin
    tenant.DeleteSiteCollection("https://tenant.sharepoint.com/sites/Test", true);

}
Gautam Sheth
  • 2,442
  • 1
  • 17
  • 16
0

Connect to SharePoint Online with global administrator account:

Connect-PnPOnline https://tenant-admin.sharepoint.com

Remove specific site collection by url:

Remove-PnPTenantSite -Url   https://tenant.sharepoint.com/sites/sitename-Force -SkipRecycleBin

Remove-PnPTenantSite

Jerry
  • 3,480
  • 1
  • 10
  • 12