Create OneDrive for Business usage report for all users

The script retrieves all SPO users and pulls usage statistics for their ODB sites. The script uses CSOM.

ODB Report.rar
 
 
 
 
 
4.8 Star
(12)
2,143 times
Add to favorites
Office 365
3/22/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Access Denied?
    6 Posts | Last post April 08, 2017
    • Thanks for posting this alternative method to grab the OD4B usage details, I just started seeing 0s using the non-SDK script as well. However, I'm trying to run this one and I'm receiving an access denied and 401 unauthorized message each time it queries someone's URL. Any ideas? I'm running the script as an O365 Global Admin.
      
      This is what it looks like for each OD4B site the script queries:
      
      Storage:
      Percentage used:
      Storage free:  1099511627776
      Processing  https://tenantname-my.sharepoint.com/personal/firstname_lastname_tenantname_com
      Exception calling "ExecuteQuery" with "0" argument(s): "Access denied. You do not have permission to perform this acti
      At C:\Users\Matt\Downloads\UsageReportWithCSOM.ps1:56 char:3
      +   $ctx.ExecuteQuery()
      +   ~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : ServerUnauthorizedAccessException
      
      
      Percentage used:
      Storage free:  1099511627776
      Processing  https://tenantname-my.sharepoint.com/personal/firstname_lastname_tenantname_com
      Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (401) Unauthorized."
      At C:\Users\Matt\Downloads\UsageReportWithCSOM.ps1:52 char:3
      +   $ctx.ExecuteQuery()
      +   ~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : WebException
      
    • If you are not currently an Administrator of the user's personal site, you can gain access using:
      
       
      Set-SPOUser -Site $urelek -LoginName $username -IsSiteCollectionAdmin $true
       
       
      In order to use the cmdlet, you can either modify the .ps1 file or write a separate script.
    • Alternatively, you could enable My Site Secondary Admin.
      
      Go to Sharepoint Admin Center
      User Profiles
      My Site settings
      Setup My Sites
      My Site Secondary Admin
      Enable this and add in your Office 365 Global Admin account
      
      Cheers
    • Thanks!
    • I tried the above suggestion and I still can't run the script.
      
      Processing  https://xxxxmy.sharepoint.com/personal/fournim1_xxxx_onmicrosoft_com
      Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (401) Unauthorized."
      At C:\output\UsageReportv2.ps1:64 char:3
      +   $ctx.ExecuteQuery()
      +   ~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : WebException
      
      Failed
    • Hi mgmjtech,
      
      Can you open  https://xxxxmy.sharepoint.com/personal/fournim1_xxxx_onmicrosoft_com in the browser?
  • Output manipulation
    1 Posts | Last post April 03, 2017
    • Hi:
      
      Thanks for the useful script.  For the v2 script, would it be possible to output the 'Storage', 'PercentUsed', and 'FreeStorage' columns into consistently more readable formats?  Sometimes the output is scientific notation (eg. 1.52143638842972E-06) and sometimes not.  Finding it hard to manipulate the data in Excel easily.
      
      Thanks.
  • Why the Free Number is 1099511627776
    4 Posts | Last post March 22, 2016
    • Thanks for your posting. But after I run the script, the free storage for all the users are 1099511627776 even if they have files in OneDrive for Business
    • Just check line 57:
      
       $outputty=1099511627776-$ctx.Site.Usage.StoragePercentageUsed
      
      I think it should be 
      
       $outputty=1099511627776-$ctx.Site.Usage.Storage
      
      So it takes away the actual storage size rather than the percentage.
    • Yes. Andrew you are correct. I found it just after I post the questions. Is that a way we can get the reports into a csv file?
    • Thank you for all the comments. I modified the subtraction and uploaded the new version.
      
      In the new version (UsageReportv2) there is also an option to export all information to a csv file. 
      
      If you have any more suggestions, please let me know.