From 99ffab2e505eed10301850fd12f43de03b358e31 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Wed, 25 May 2022 23:41:16 +0300 Subject: [PATCH 1/4] Fix #1554 - issue with onedrive site storage quota --- .../UserProfiles/GetUserOneDriveQuota.cs | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Commands/UserProfiles/GetUserOneDriveQuota.cs b/src/Commands/UserProfiles/GetUserOneDriveQuota.cs index 409e5d28d..1a7b9d56b 100644 --- a/src/Commands/UserProfiles/GetUserOneDriveQuota.cs +++ b/src/Commands/UserProfiles/GetUserOneDriveQuota.cs @@ -1,4 +1,7 @@ -using System.Management.Automation; +using System.Collections.Generic; +using System.Linq; +using System.Management.Automation; +using Microsoft.Online.SharePoint.TenantAdministration; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.UserProfiles; @@ -16,9 +19,43 @@ public class GetUserOneDriveQuota : PnPAdminCmdlet protected override void ExecuteCmdlet() { var peopleManager = new PeopleManager(ClientContext); - var oneDriveQuota = peopleManager.GetUserOneDriveQuotaMax(Account); + + var result = Tenant.EncodeClaim(Account); + ClientContext.ExecuteQueryRetry(); + Account = result.Value; + + var properties = peopleManager.GetPropertiesFor(Account); + ClientContext.Load(properties); ClientContext.ExecuteQueryRetry(); - WriteObject(oneDriveQuota); + + var personalSiteUrl = properties.PersonalUrl; + + SPOSitePropertiesEnumerableFilter filter = new SPOSitePropertiesEnumerableFilter() + { + IncludePersonalSite = PersonalSiteFilter.Include, + IncludeDetail = true, + Template = "SPSPERS" + }; + + var sitesList = Tenant.GetSitePropertiesFromSharePointByFilters(filter); + var sites = new List(); + do + { + Tenant.Context.Load(sitesList); + Tenant.Context.ExecuteQueryRetry(); + sites.AddRange(sitesList.ToList()); + } while (!string.IsNullOrWhiteSpace(sitesList.NextStartIndexFromSharePoint)); + + var userSite = sitesList.Where(s => s.Url.ToLower() == personalSiteUrl.TrimEnd('/').ToLower()).FirstOrDefault(); + + if (userSite != null) + { + WriteObject(userSite.StorageMaximumLevel * 1024 * 1024); + } + else + { + WriteWarning("Couldn't find quota for the specified personal site"); + } } } } \ No newline at end of file From 4f3680dd74163379c0735e025089076db8ba8414 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Sun, 12 Jun 2022 23:58:30 +0300 Subject: [PATCH 2/4] Fixed to a better filter --- src/Commands/UserProfiles/GetUserOneDriveQuota.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Commands/UserProfiles/GetUserOneDriveQuota.cs b/src/Commands/UserProfiles/GetUserOneDriveQuota.cs index 1a7b9d56b..56bd5fd40 100644 --- a/src/Commands/UserProfiles/GetUserOneDriveQuota.cs +++ b/src/Commands/UserProfiles/GetUserOneDriveQuota.cs @@ -34,7 +34,8 @@ protected override void ExecuteCmdlet() { IncludePersonalSite = PersonalSiteFilter.Include, IncludeDetail = true, - Template = "SPSPERS" + Template = "SPSPERS", + Filter = $"Url -eq '{personalSiteUrl.TrimEnd('/')}'" }; var sitesList = Tenant.GetSitePropertiesFromSharePointByFilters(filter); @@ -54,7 +55,7 @@ protected override void ExecuteCmdlet() } else { - WriteWarning("Couldn't find quota for the specified personal site"); + WriteWarning($"Couldn't find onedrive quota for the account: {Account} "); } } } From 118c6d0613e78c5688f07f482f15608cfee81ae1 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 15 Jun 2022 01:30:10 +0200 Subject: [PATCH 3/4] Adding changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff71cab7..a45d2d6ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed Graph endpoints for non-commercial clouds for Managed Identity and Teams cmdlets [#1944](https://github.com/pnp/powershell/pull/1944) - Fixed `Add-PnPTeamsUser`, the parameter `-Channel` is now not required. [#1953](https://github.com/pnp/powershell/pull/1953) - Fixed `Get-PnPPlannerTask` throwing an object reference exception for completed tasks [#1956](https://github.com/pnp/powershell/issues/1956) +- Fixed `Get-PnPUserOneDriveQuota` returning the maximum possible quota instead of the actual configured quota on a OneDrive for Business site [#1902](https://github.com/pnp/powershell/pull/1902) ### Removed - Removed `Get-PnPAvailableClientSideComponents`. Use `Get-PnPPageComponent -Page -ListAvailable` instead. [#1833](https://github.com/pnp/powershell/pull/1833) From beb8874417c48b4776b0a79c7bbe44f31ccc4edf Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Wed, 15 Jun 2022 01:35:12 +0200 Subject: [PATCH 4/4] Updated documentation --- documentation/Get-PnPUserOneDriveQuota.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/documentation/Get-PnPUserOneDriveQuota.md b/documentation/Get-PnPUserOneDriveQuota.md index 5f9318874..a5e2f629c 100644 --- a/documentation/Get-PnPUserOneDriveQuota.md +++ b/documentation/Get-PnPUserOneDriveQuota.md @@ -15,7 +15,7 @@ online version: https://pnp.github.io/powershell/cmdlets/Get-PnPUserOneDriveQuot * SharePoint: Access to the SharePoint Tenant Administration site -Retrieves the current quota set on the OneDrive for Business site for a specific user +Retrieves the current quota set on the OneDrive for Business site for a specific user in bytes. ## SYNTAX @@ -24,7 +24,7 @@ Get-PnPUserOneDriveQuota [-Account] [-Connection ] [-admin.sharepoint.com) with Connect-PnPOnline in order to use this cmdlet. +This command allows you to request the quota set on the OneDrive for Business site of a specific user. ## EXAMPLES @@ -33,7 +33,14 @@ This command allows you to request the quota set on the OneDrive for Business si Get-PnPUserOneDriveQuota -Account 'user@domain.com' ``` -Returns the quota set on the OneDrive for Business site for the specified user +Returns the quota set on the OneDrive for Business site for the specified user in bytes + +### EXAMPLE 2 +```powershell +(Get-PnPUserOneDriveQuota -Account 'user@domain.com') / 1gb +``` + +Returns the quota set on the OneDrive for Business site for the specified user in gigabytes ## PARAMETERS @@ -67,5 +74,4 @@ Accept wildcard characters: False ## RELATED LINKS -[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file