List, Remove And Restore Deleted Site Using Microsoft 365 CLI

Introduction

Your deleted current SharePoint sites will not vanish from the UI before they have been eliminated from the recycle bin in the tenant. Erased SharePoint destinations are helping for 93 days. Sites, all their substance and settings are for all time erased, including records, libraries, pages, and any subsites.

To reuse a URL from an erased site(reproduce a site), you need to erase the site, it may require as long as 24 hours for the URL to open up. You can either hang tight for a quarter of a year. Erase them physically by the SharePoint administrator, or run the CLI for Microsoft 365 content underneath.

Installation of Microsoft 365 CLI

Regardless of the off chance that you are on Windows, macOS, or Linux, utilizing bash, Cmder or PowerShell, utilizing the CLI for Microsoft 365 you can design Microsoft 365, oversee SharePoint Framework ventures, and construct computerization.

The CLI for Microsoft 365 is distributed as an NPM package. To use it, install it using the below command.

npm i -g @pnp/cli-microsoft365
m365 login

List Remove and Restore Deleted Site

Copy https://microsoft.com/devicelogin and paste it into the browser.

Microsoft

Get all Deleted Sites from the Tenant Recycle Bin

m365 spo tenant recyclebinitem list [options]

Yield as underneath.

C:\Users\Dips3>m365 spo tenant recyclebinitem list

DaysRemaining DeletionTime                                     Url
------------- --------------------------------------------------- ---------------------------------------------------
92            Fri May 07 2021 15:30:55 GMT+0530 (India Standard Time) https://dev1802.sharepoint.com/sites/SampleTeamSite
92            Fri May 07 2021 15:30:52 GMT+0530 (India Standard Time) https://dev1802.sharepoint.com/sites/Viva-Communication
92            Fri May 07 2021 15:30:56 GMT+0530 (India Standard Time) https://dev1802.sharepoint.com/sites/Viva-Team

C:\Users\Dips3>m365 spo tenant recyclebinitem list -o json

[
  {
    "_ObjectType_": "Microsoft.Online.SharePoint.TenantAdministration.DeletedSiteProperties",
    "_ObjectIdentity_": "6c9bc59f-b03f-0000-7fdb-2a757bad1669|908bed80-a04a-4433-b4a0-883d9847d110:3d24e369-128a-419f-a457-659738339df3\nDeletedSiteProperties\nhttps%3a%2f%2fdev1802.sharepoint.com%2fsites%2fSampleTeamSite",
    "DaysRemaining": 92,
    "DeletionTime": "/Date(2021,4,7,15,30,55,3)/",
    "SiteId": "/Guid(71145661-b598-4780-925c-25df3a7b2353)/",
    "Status": "Recycled",
    "StorageMaximumLevel": 26214400,
    "Url": "https://dev1802.sharepoint.com/sites/SampleTeamSite",
    "UserCodeMaximumLevel": 300
  }
]

Remove site from recycle bin permanently.

m365 spo tenant recyclebinitem remove [options]

Yield as underneath.

C:\Users\Dips3>m365 spo tenant recyclebinitem remove --url https://dev1802.sharepoint.com/sites/Viva-Team
? Are you sure you want to remove the deleted site collection https://dev1802.sharepoint.com/sites/Viva-Team from tenant recycle bin? Yes

Restore Deleted Site.

m365 spo tenant recyclebinitem restore [options]

Yield as underneath,

C:\Users\Dips3>m365 spo tenant recyclebinitem restore --url https://dev1802.sharepoint.com/sites/Viva-Communication
Delete all sites permanently in one shot,
$Sites = m365 spo tenant recyclebinitem list -o json | ConvertFrom-Json
$Sites | Format-Table Url

if ($Sites.Count -gt 0) {
    for ($index = 0; $index -lt $Sites.Count; $index++) {
        m365 spo tenant recyclebinitem remove -u $Sites[$index].Url --confirm
    }
}

Reference URLs

happy coding


Similar Articles