How can i get a list of OneDrive for Business sites in the tenant - showing storage etc using PnP

Iron Contributor

Hi there,
I want to be able to list all onedrive url and also their storage and current usage using PnP Powershell.
I ran the script below but the storagequote and current usage was blank

$ODFBSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal/ -and Url -like domainname'"| Select-Object Owner, Title, URL, StorageQuota, StorageUsageCurrent | Sort-Object StorageUsageCurrent -Desc

$TotalODFBGBUsed = [Math]::Round(($ODFBSites.StorageUsageCurrent | Measure-Object -Sum).Sum /1024,2)
$Report = @()
ForEach ($Site in $ODFBSites) {
      $ReportLine = [PSCustomObject][Ordered]@{
             Owner    = $Site.Title
             Email    = $Site.Owner
             URL      = $Site.URL
             QuotaGB  = [Math]::Round($Site.StorageQuota/1024,2) 
             UsedGB   = [Math]::Round($Site.StorageUsageCurrent/1024,4) }
      $Report += $ReportLine }
$Report | Export-CSV -NoTypeInformation c:\somepathtoadrive

 

Any ideas what i'm missing or is not possible using PnP?

Thanks in Advance

3 Replies

Hello @Patrick Rote,

Did you try -Detailed ?

By default, not all returned attributes are populated.

Reference: Get-PnPTenantSite Documentation

Hope that helps.

 

@Patrick Rote,

I think you are selecting wrong properties...

QuotaGB should be StorageMaximumLevel and UsedGB should be StorageUsage.

So your code will look something like this:

$ODFBSites = Get-PnPTenantSite -IncludeOneDriveSites -Filter "Url -like '-my.sharepoint.com/personal'"
$Report = @()
ForEach ($Site in $ODFBSites) {
      $ReportLine = [PSCustomObject][Ordered]@{
             Owner    = $Site.Title
             Email    = $Site.Owner
             URL      = $Site.URL
             QuotaGB  = [Math]::Round($Site.StorageMaximumLevel/1024,2) 
             UsedGB   = [Math]::Round($Site.StorageUsage/1024,4) }
      $Report += $ReportLine }

Hope that helps.