Skip to content

Fix #1554 - issue with onedrive site storage quota #1902

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 5 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 11 additions & 5 deletions documentation/Get-PnPUserOneDriveQuota.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -24,7 +24,7 @@ Get-PnPUserOneDriveQuota [-Account] <String> [-Connection <PnPConnection>] [<Com
```

## DESCRIPTION
This command allows you to request the quota set on the OneDrive for Business site of a specific user. You must connect to the tenant admin website (https://:<tenant>-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

Expand All @@ -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

Expand Down Expand Up @@ -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)
44 changes: 41 additions & 3 deletions src/Commands/UserProfiles/GetUserOneDriveQuota.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,9 +19,44 @@ 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",
Filter = $"Url -eq '{personalSiteUrl.TrimEnd('/')}'"
};

var sitesList = Tenant.GetSitePropertiesFromSharePointByFilters(filter);
var sites = new List<SiteProperties>();
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 onedrive quota for the account: {Account} ");
}
}
}
}