问题
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?
回答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);
}
回答2:
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
来源:https://stackoverflow.com/questions/55722180/how-to-delete-sharepoint-site-collection-using-pnp-csom-programmatically