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

%3CLINGO-SUB%20id%3D%22lingo-sub-1969728%22%20slang%3D%22en-US%22%3EHow%20can%20i%20get%20a%20list%20of%20OneDrive%20for%20Business%20sites%20in%20the%20tenant%20-%20showing%20storage%20etc%20using%20PnP%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1969728%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20there%2C%3CBR%20%2F%3EI%20want%20to%20be%20able%20to%20list%20all%20onedrive%20url%20and%20also%20their%20storage%20and%20current%20usage%20using%20PnP%20Powershell.%3CBR%20%2F%3EI%20ran%20the%20script%20below%20but%20the%20storagequote%20and%20current%20usage%20was%20blank%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%24ODFBSites%20%3D%20Get-PnPTenantSite%20-IncludeOneDriveSites%20-Filter%20%22Url%20-like%20'-my.sharepoint.com%2Fpersonal%2F%20-and%20Url%20-like%20domainname'%22%7C%20Select-Object%20Owner%2C%20Title%2C%20URL%2C%20StorageQuota%2C%20StorageUsageCurrent%20%7C%20Sort-Object%20StorageUsageCurrent%20-Desc%0A%0A%24TotalODFBGBUsed%20%3D%20%5BMath%5D%3A%3ARound((%24ODFBSites.StorageUsageCurrent%20%7C%20Measure-Object%20-Sum).Sum%20%2F1024%2C2)%0A%24Report%20%3D%20%40()%0AForEach%20(%24Site%20in%20%24ODFBSites)%20%7B%0A%20%20%20%20%20%20%24ReportLine%20%3D%20%5BPSCustomObject%5D%5BOrdered%5D%40%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20Owner%20%20%20%20%3D%20%24Site.Title%0A%20%20%20%20%20%20%20%20%20%20%20%20%20Email%20%20%20%20%3D%20%24Site.Owner%0A%20%20%20%20%20%20%20%20%20%20%20%20%20URL%20%20%20%20%20%20%3D%20%24Site.URL%0A%20%20%20%20%20%20%20%20%20%20%20%20%20QuotaGB%20%20%3D%20%5BMath%5D%3A%3ARound(%24Site.StorageQuota%2F1024%2C2)%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20UsedGB%20%20%20%3D%20%5BMath%5D%3A%3ARound(%24Site.StorageUsageCurrent%2F1024%2C4)%20%7D%0A%20%20%20%20%20%20%24Report%20%2B%3D%20%24ReportLine%20%7D%0A%24Report%20%7C%20Export-CSV%20-NoTypeInformation%20c%3A%5Csomepathtoadrive%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20ideas%20what%20i'm%20missing%20or%20is%20not%20possible%20using%20PnP%3F%3C%2FP%3E%3CP%3EThanks%20in%20Advance%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1969728%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1973936%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20i%20get%20a%20list%20of%20OneDrive%20for%20Business%20sites%20in%20the%20tenant%20-%20showing%20storage%20etc%20using%20Pn%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1973936%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F89836%22%20target%3D%22_blank%22%3E%40Patrick%20Rote%3C%2FA%3E%2C%3C%2FP%3E%3CP%3EDid%20you%20try%20%3CSTRONG%3E-Detailed%3C%2FSTRONG%3E%20%3F%3C%2FP%3E%3CP%3EBy%20default%2C%20not%20all%20returned%20attributes%20are%20populated.%3C%2FP%3E%3CP%3EReference%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fsharepoint-pnp%2Fget-pnptenantsite%3Fview%3Dsharepoint-ps%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGet-PnPTenantSite%20Documentation%3C%2FA%3E%3C%2FP%3E%3CP%3EHope%20that%20helps.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1974711%22%20slang%3D%22en-US%22%3ERe%3A%20How%20can%20i%20get%20a%20list%20of%20OneDrive%20for%20Business%20sites%20in%20the%20tenant%20-%20showing%20storage%20etc%20using%20Pn%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1974711%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F672105%22%20target%3D%22_blank%22%3E%40AndySvints%3C%2FA%3E%26nbsp%3B%20Thanks%20but%20it%20doesn't%20get%20the%20Storage%20%3A(%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
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.