Создание отчета о файлах для счета one drive for business

Featured image of post Find / Restore Deleted OneDrive Sites with PnP PowerShell


Microsoft365


PowerShell

In this blog post, learn how to restore a deleted OneDrive site in SharePoint Online using PowerShell.

Introduction

Prerequisites

  • A SharePoint Online tenant administrator account
  • PowerShell 7.2 or later installed on your computer
  • The PnP PowerShell module installed on your computer

Script Overview

The “Get-deleted-OneDrives.ps1” script is a PowerShell script that uses the PnP PowerShell module to restore a deleted OneDrive site. Here’s an overview of what the script does:

  1. Connects to SharePoint Online using the Connect-PnPOnline cmdlet.
  2. Retrieves a list of all deleted OneDrive sites using the Get-PnPTenantDeletedSite cmdlet.
  3. Filters the list of deleted OneDrive sites to find the site that matches the specified user name using the Where-Object cmdlet.
  4. Restores the deleted OneDrive site using the Restore-PnPTenantSite cmdlet.
  5. Checks if the site was successfully restored using the Get-PnPTenantSite cmdlet.
  6. Disconnects from SharePoint Online using the Disconnect-PnPOnline cmdlet.

Let’s take a closer look at each step of the script.

Step 2: Retrieve a List of Deleted OneDrive Sites

In the script, the -IncludeOnlyPersonalSite parameter is used to retrieve only deleted OneDrive sites.

 

Step 3: Filter the List of Deleted OneDrive Sites

Step 4: Restore the Deleted OneDrive Site

The fourth step of the script is to restore the deleted OneDrive site using the Restore-PnPTenantSite cmdlet. This cmdlet requires the URL of the deleted site and the -Force parameter to confirm the restoration.

In the script, the URL of the OneDrive site that was found in step 3 is used as the URL parameter for the Restore-PnPTenantSite cmdlet.

 

Step 5: Check if the Site was Restored

The fifth step of the script is to check if the OneDrive site was successfully restored using the Get-PnPTenantSite cmdlet. This cmdlet requires the URL of the site that was restored.

In the script, the URL of the OneDrive site that was found in step 3 is used as the URL parameter for the Get-PnPTenantSite cmdlet.

:/>  Управление лицензиями с помощью SLMGR
 

The whole script looks like this:

 #Restore deleted OneDrive #Check if Site was restored 

Conclusion

Comments

You can use your Mastodon account to reply to this post. Learn how this is implemented here.

Reply to ollimenzel’s post

With an account on the Fediverse or Mastodon, you can respond to this post.
Since Mastodon is decentralized, you can use your existing account hosted by another Mastodon server or compatible platform if you don’t have an account on this one.

Copy and paste this URL into the search field of your favourite Fediverse app or the web interface of your Mastodon server.

Practical Graph: Create a Files Report for a OneDrive for Business Account

OneDrive is the Great Dumping Ground for Microsoft 365 Information

Создание отчета о файлах для счета one drive for business

Reporting OneDrive Files

Adapting Script Code for OneDrive

Permissions

  • Files.Read.All: Access files in any OneDrive account that the signed in user is allowed to view.
  • RecordsManagement.Read.All: Read information about retention labels.
  • InformationProtectionPolicy.Read: Read information about sensitivity labels.

Essentially, all the data about files ends up in a PowerShell list that we can query to slice and dice the information to discover different aspects of the content held in OneDrive.

Files in a OneDrive for Business account.
Figure 1: Files in a OneDrive for Business account

Создание отчета о файлах для счета one drive for business

Analyzing the Data

The basic information I want to know about a OneDrive account is:

  • How many files are in the account.
  • What kind of files are in the account.
  • How much quota is used and how much remains.
  • What file types occupy most space.
  • The number of files that have retention and sensitivity labels.

I’m sure that your imagination will come up with other insights that could be generated from the data. That’s the joy of PowerShell: create data and then decide how to use it. Figure 1 shows the analysis for the points listed above. My OneDrive for Business account has existed since 2013, so it’s not hard to understand how some of the debris accrued.

Statistics for a OneDrive for Business account
Figure 2: Statistics for a OneDrive for Business account

Unsurprisingly, the account holds a lot of Word. PDF, and PowerPoint files. There’s also lots of PowerShell files, probably the remnants of some badly managed installations.

Retention and Sensivity label usage in a OneDrive for Business account.
Figure 3: Retention and Sensivity label usage in a OneDrive for Business account

The reported files don’t include items in the recycle bin. A beta Graph API for listing items in the recycle bin is available that doesn’t seem to extend to OneDrive for Business.

:/>  Я собрал бюджетный набор для IRL-стриминга на Raspberry Pi. Часть первая — бондинг — Личный опыт на

You can download the complete script from GitHub.

Contemplating File Statistics

Overall, I struggle to use the 5 TB quota assigned to my OneDrive account. The availability of massive storage is certainly a justification for not bothering too much about the digital debris that accumulates over time alongside the valuable content in a OneDrive for Business account. After all, if Microsoft makes the storage available, why not fill it?

Seriously, it’s a good idea to perform regular housekeeping to keep debris under control. The report helps by exposing items that might remain invisible through the OneDrive GUI unless you go looking for specific information. I like that and have removed a thousand files since I started to develop the script. Maybe it can help you to clean up too.

About the Author

Tony Redmond has written thousands of articles about Microsoft technology since 1996. He is the lead author for the Office 365 for IT Pros eBook, the only book covering Office 365 that is updated monthly to keep pace with change in the cloud. Apart from contributing to Practical365.com, Tony also writes at Office365itpros.com to support the development of the eBook. He has been a Microsoft MVP since 2004.