Forum Discussion

Patrick Rote's avatar
Patrick Rote
Iron Contributor
Dec 09, 2020

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

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

      • AndySvints's avatar
        AndySvints
        Steel Contributor

        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.

Resources