Manage Deleted SharePoint Sites Using PowerShell

Manage Deleted SharePoint Sites Using PowerShell

In the current era of rapid digital advancements, Microsoft 365 organizations constantly modify, delete, and create SharePoint Online sites as part of their information management and collaboration processes. However, the task of managing deleted sites may be a little bit tough, if you don’t know the right way to manage deleted SharePoint sites. This is also challenging, particularly when dealing with a large number of sites.

Though the SharePoint admin center provides a user-friendly interface for managing SharePoint, it may not always be suited for handling large-scale tasks across multiple deleted sites. Luckily, PowerShell offers a robust solution for efficiently managing bulk operations on deleted SharePoint sites.

In this blog, we will explore how PowerShell can be used to manage deleted SharePoint sites effectively to maintain a streamlined SharePoint environment.

What are the Reasons to Manage Deleted SharePoint Sites?

The following are the major reasons to manage deleted SharePoint sites.

Accidental Deletion of SharePoint Online Sites: Accidental deletion of SharePoint Online sites is a common occurrence, often resulting from human error or other unforeseen circumstances. Implementing efficient management practices is vital in such scenarios for the restoration of deleted sites.

Microsoft 365 Data Retrieval: In situations where essential data from a deleted SharePoint site is needed, restoration of sites can help retrieve important documents, lists, libraries, etc.

Revived Businesses Using SharePoint Online: In the event of a deprecated business being revived or reinstated, there is often a need to restore SharePoint sites to resume operations smoothly. This could occur due to various reasons such as rebranding, restructuring, or acquisitions.

Reclaiming Deleted SharePoint Site’s URL: When you need to reuse a URL which is still associated with the deleted site, you have two options: Permanent deletion is preferred for creating a new site without manual content deletion. Restoration requires deleting existing content and files. After permanent deletion, the URL may take around 24 hours to become available for reuse.

Storage Space Optimization in Office 365: SharePoint sites can consume storage space, and the accumulation of unused or outdated sites can lead to storage constraints. Deleting unnecessary SharePoint sites helps optimize and manage SPO storage quota to mitigate capacity issues.

What Happens When You Delete a SharePoint Site?

When a SharePoint Online site is deleted, it is retained in the site collection recycle bin for a period of 93 days. Beyond that timeframe, all content within the site, including document libraries, files, site settings, history, and any associated subsites and their contents, is permanently removed.

Note: Unlike SharePoint Online sites, which are retained in the site collection recycle bin, deleted files in a SharePoint site are kept in the site recycle bin. Furthermore, you have the ability to manage the recycle bin of a SharePoint site.

Manage Deleted SharePoint Sites Using PowerShell

To manage deleted SharePoint Online sites using PowerShell, you must first install and connect to SharePoint Online PowerShell as a site collection administrator. Below are the operations to manage deleted SharePoint sites using PowerShell.

List All Deleted SharePoint Online Sites in Microsoft 365

Listing SharePoint deleted sites can assist in managing and performing various actions, such as site restoration, permanent deletion, etc. To list all deleted SharePoint Online sites in Microsoft 365 using PowerShell, you can use the following cmdlet.

Get-SPODeletedSite -Limit All

List All Deleted SharePoint Online Sites in Microsoft 365By the way, execution of this cmdlet retrieves important details such as storage quota, resource quota, deletion time, and the number of days remaining until the site is permanently deleted.

Note: By default, the cmdlet exclusively retrieves site and site collections that are not considered as Personal Sites (My Sites). If you want to include personal sites in the results, you can utilize the -IncludePersonalSite” parameter. Conversely, if you only wish to obtain Personal Sites, you can utilize the “-IncludeOnlyPersonalSite” parameter.

Restore a Deleted SharePoint Online Site using PowerShell

Restoring a SharePoint Online site allows you to recover its content, configuration, and permissions, making it accessible to users once again. To restore a deleted SharePoint Online site using PowerShell, run the following cmdlet.

Restore-SPODeletedSite -Identity <SPOSiteURL>

Likewise, if you are interested in knowing more about recovering deleted OneDrive, you can refer to the blog on how to restore a deleted OneDrive.

Restore Deleted SharePoint Online Sites in Bulk

Bulk restoration of SharePoint Online sites refers to the process of restoring multiple deleted sites in SPO simultaneously. To do so, create a CSV file with the list of SPO sites’ URL that needs to be restored.

CSV File for Restore Deleted SharePoint Online Sites in Bulk

After the creation of the CSV file, you can run the following cmdlet to restore the list of SPO deleted sites.

Import-Csv <FileLocation> | foreach {Restore-SPODeletedSite -Identity $_.SPOSitesUrl}

Replace <FileLocation> with the appropriate file path of the created CSV file.

You can also restore all the deleted SPO sites with the help of the following cmdlet.

Get-SPODeletedSite | foreach {Restore-SPODeletedSite -Identity $_.Url}

Permanently Delete a SharePoint Online Site Using PowerShell

Before proceeding with deletions , it’s crucial to assess which sites and subsites are no longer necessary. PowerShell scripts can help you list all sites and subsites separately, enabling informed decisions for site cleanup and data management. Permanently deleting SPO sites refers to the action of erasing all data and settings associated with the site before its 93 days retention period. You can make use of the following cmdlet to do the permanent deletion.

Remove-SPODeletedSite -Identity <SPOSiteURL>

The execution of the above cmdlet asks for confirmation of the permanent deletion of SharePoint sites. To skip the confirmation prompt and proceed with the permanent deletion directly, use the Confirm:$false parameter.

Warning: Once a SharePoint Online site is permanently deleted, the site contents and the associated data cannot be recovered.

Permanently Delete Multiple SharePoint Online Sites

Permanent deletion of SPO sites refers to the process of removing multiple deleted sites in SPO simultaneously. To do so, create a CSV file with the list of SPO sites’ URL that needs to be permanently deleted.

CSV File for Permanent Deletion of Multiple SharePoint Online Sites

After the creation of the CSV file, you can run the following cmdlet to permanently remove the list of SPO deleted sites.

Import-Csv <FileLocation>| foreach {Remove-SPODeletedSite -Identity $_.SPOSitesUrl -Confirm:$false}

Replace <FileLocation> with the appropriate file path of the created CSV file.

You can also permanently delete all the deleted SPO sites with the help of the following cmdlet.

Get-SPODeletedSite | foreach {Remove-SPODeletedSite -Identity $_.Url -Confirm:$false}

Take Control Over Deleted SharePoint Sites Using AdminDroid!

Why go through the hassle of managing SharePoint Online sites using PowerShell? AdminDroid simplifies this process by providing detailed insights through the following SharePoint Online Site Reports.

  • All SharePoint Sites Information
  • Recycle Bin Disabled Sites
  • Recently Created SharePoint Sites
  • SharePoint Site Sharing Configurations
  • SharePoint Sites with Custom Permission
  • Project Web Apps SPO sites

Moreover, AdminDroid’s SharePoint Online auditing tool provides comprehensive reports on various SPO operations such as SharePoint sites and group changes, site access permissions changes, file & folder activities, and other SharePoint access related activities.

SharePoint Deleted Site Collection Report Using AdminDroid

SharePoint Sites Deleted by Users Report - AdminDroid

Additionally, AdminDroid SharePoint Online management tool offers a wide range of over 180+ reports, providing comprehensive insights into every aspect of your SharePoint Online environment. Gain in-depth details on your site collections, identify inactive SharePoint Online sites, optimize lists and libraries, and analyze site usage across your organization.

Elevate your Office 365 insights with AdminDroid Microsoft 365 reporting tool with over 1800+ comprehensive reports and 30+ visually stunning dashboards. Dive into the depths of your Office 365 environment with advanced capabilities such as reporting, auditing, analytics, usage statistics, security & compliance, etc.

Unlock the full potential of your SPO environment and take control of your organization’s collaboration and 🚀 productivity with AdminDroid.

We hope that this blog will help you to manage deleted SharePoint sites effectively using PowerShell. Feel free to reach us in the comments section for any assistance.

Manage Deleted SharePoint Sites Using PowerShell

by Thiraviam time to read: 5 min
0