question

Hokez avatar image
0 Votes"
Hokez asked XuyanDingMSFT-4872 commented

Delete SharePoint Online site collections using powershell

Hello,

I have been trying to delete site collections from a csv, I'm trying to use a powershell script to get the site URLs to be deleted.

I've tried everything, now that I've run out of ideas I'm opening this question. I'm accepting possibilities other than Powershell

PS: I'm trying to do this without creating anything in the tenant.

This site belongs to a Microsoft 365 group. To delete the site, you must delete the group.

200674-screenshot-57.png

Below are some attempts:


 #Modules
 Import-Module ExchangeOnlineManagement
 Import-Module Microsoft.Online.SharePoint.PowerShell
 Import-Module SharePointPnPPowerShellOnline
        
 $site = "https://tenant.sharepoint.com/sites/site"
 $mailGroup = "group@onmicrosoft.com"
        
 #First
 Remove-UnifiedGroup -Identity $mailGroup-Confirm:$false
 Remove-SPOSite -Identity $site -NoWait -Confirm:$false
        
 #Second
 Remove-UnifiedGroup -Identity $mailGroup-Confirm:$false
        
 Set-SPOSite -Identity $site  -LockState "unlock" 
 Set-SPOSite -Identity $site  -Owner $userCredential.UserName
 Remove-SPOSite -Identity $site -NoWait -Confirm:$false
        
 #Third
 $SharepointSite = Get-SPOSite $site
 Remove-PnPUnifiedGroup -Identity $SharepointSite .GroupID
 Remove-PnPTenantSite $site

I also tried what is in the link: https://docs.microsoft.com/en-us/answers/questions/674248/batch-delete-site-collections-in-powershell-from-c.html






office-sharepoint-onlinewindows-server-powershell
screenshot-57.png (41.6 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for your question. We are currently looking into this issue and will give you an update as soon as possible. Thank you for your understanding and support.

0 Votes 0 ·

1 Answer

XuyanDingMSFT-4872 avatar image
0 Votes"
XuyanDingMSFT-4872 answered XuyanDingMSFT-4872 commented

Hi @Hokez,

You could delete the group associated with the site collection. After deleting the Microsoft 365 group, you should wait for a while and the site will be automatically deleted.

PowerShell command:

 #Parameters
 $AdminCenterURL="https://tenant-admin.sharepoint.com"
 $GroupSiteURL="https://tenant.sharepoint.com/sites/site"
    
 #Connect to SharePoint Online
 Connect-SPOService -Url $AdminCenterURL
    
 #Unlock the Group site Collection
 Set-SPOSite -Identity $GroupSiteURL -LockState unlock
    
 Remove-UnifiedGroup -Identity "group name"



If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Hokez,

Is there any progress on this thread? Please feel free to let me know.

0 Votes 0 ·

Hi @Hokez,

Is there anything else I can help with regarding this issue?

You can comment us at any time and we will continue to follow up.

0 Votes 0 ·

Hi @Hokez,

I am checking to see if the problem has been resolved . If you have any questions you can feel free to contact me.

0 Votes 0 ·