diff --git a/documentation/Get-PnPContainer.md b/documentation/Get-PnPContainer.md index de71726b5..eff80e718 100644 --- a/documentation/Get-PnPContainer.md +++ b/documentation/Get-PnPContainer.md @@ -20,7 +20,7 @@ Returns one or more Containers in a SharePoint repository services application. ## SYNTAX ```powershell -Get-PnPContainer [-Identity ] [-OwningApplicationId ] [-Paged ] [-PagingToken ][-Connection ] +Get-PnPContainer [-Identity ] [-OwningApplicationId ] [-Paged ] [-PagingToken ][-SortOrder ] [-Connection ] ``` ## DESCRIPTION @@ -116,6 +116,7 @@ Accept wildcard characters: False ### -PagingToken Use this parameter to provide the provided to view the remaining Containers as shown in Example 5. If there are no more Containers to display, the commandlet output will return the message End of Containers view. Otherwise, use the given to retrieve the next batch of up to 5,000 ontainers. + ```yaml Type: String Parameter Sets: (All) @@ -126,6 +127,22 @@ Default value: False Accept pipeline input: False Accept wildcard characters: False ``` + +### -SortOrder + +Use this parameter to specify the sort order. The sorting will be done based on Storage used in ascending or descending order. + +```yaml +Type: SortOrder +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ## RELATED LINKS [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) \ No newline at end of file diff --git a/src/Commands/Admin/GetContainer.cs b/src/Commands/Admin/GetContainer.cs index 7128bdf9e..454c2c481 100644 --- a/src/Commands/Admin/GetContainer.cs +++ b/src/Commands/Admin/GetContainer.cs @@ -1,8 +1,11 @@ using Microsoft.Online.SharePoint.TenantAdministration; +using Microsoft.Online.SharePoint.TenantManagement; using Microsoft.SharePoint.Client; using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Model.SharePoint; using System; +using System.Collections.Generic; using System.Management.Automation; namespace PnP.PowerShell.Commands.Admin @@ -23,6 +26,9 @@ public class GetContainer : PnPAdminCmdlet [Parameter(Mandatory = false)] public string PagingToken { get; set; } + [Parameter(Mandatory = false)] + public SortOrder? SortByStorage { get; set; } + protected override void ExecuteCmdlet() { if (Identity != null) @@ -32,9 +38,36 @@ protected override void ExecuteCmdlet() } else if (OwningApplicationId != Guid.Empty) { - var containersProperties = Tenant.GetSPOContainersByApplicationId(OwningApplicationId, Paged, PagingToken); + ClientResult clientResult; + if (SortByStorage.HasValue) + { + bool ascending = SortByStorage == SortOrder.Ascending; + clientResult = Tenant.GetSortedSPOContainersByApplicationId(OwningApplicationId, ascending, Paged, PagingToken); + } + else + { + clientResult = Tenant.GetSPOContainersByApplicationId(OwningApplicationId, Paged, PagingToken); + } AdminContext.ExecuteQueryRetry(); - WriteObject(containersProperties.Value.ContainerCollection); + IList containerCollection = clientResult.Value.ContainerCollection; + if (containerCollection != null && containerCollection.Count > 0) + { + foreach (SPContainerProperties item in containerCollection) + { + WriteObject(new Model.SharePoint.SPConsumingTenantContainerByIdentity(item)); + } + if (Paged) + { + if (!string.IsNullOrWhiteSpace(clientResult.Value.PagingToken)) + { + WriteObject($"Retrieve remaining containers with token: {clientResult.Value.PagingToken}"); + } + else + { + WriteObject("End of containers view."); + } + } + } } else { diff --git a/src/Commands/Model/SharePoint/SPConsumingTenantContainersByOwningAppId.cs b/src/Commands/Model/SharePoint/SPConsumingTenantContainersByOwningAppId.cs new file mode 100644 index 000000000..5ac156fbe --- /dev/null +++ b/src/Commands/Model/SharePoint/SPConsumingTenantContainersByOwningAppId.cs @@ -0,0 +1,86 @@ +using Microsoft.Graph; +using Microsoft.Online.SharePoint.TenantAdministration; +using Microsoft.Online.SharePoint.TenantManagement; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace PnP.PowerShell.Commands.Model.SharePoint +{ + public class SPConsumingTenantContainerByIdentity + { + + public string ContainerId { get; private set; } + + public string ContainerName { get; private set; } + + public string Description { get; private set; } + + public Guid OwningApplicationId { get; private set; } + + public string OwningApplicationName { get; private set; } + + public string ContainerApiUrl { get; private set; } + + public string ContainerSiteUrl { get; private set; } + + public string SensitivityLabel { get; private set; } + + public IList Owners { get; private set; } + + public IList Managers { get; private set; } + + public IList Readers { get; private set; } + + public IList Writers { get; private set; } + + public DateTime CreatedOn { get; private set; } + + public long StorageUsedInBytes { get; private set; } + + public SPOConditionalAccessPolicyType ConditionalAccessPolicy { get; private set; } + + public bool AllowEditing { get; private set; } + + public SPOLimitedAccessFileType LimitedAccessFileType { get; private set; } + + public bool ReadOnlyForUnmanagedDevices { get; private set; } + + public string AuthenticationContextName { get; private set; } + + public bool BlockDownloadPolicy { get; private set; } + + public bool ReadOnlyForBlockDownloadPolicy { get; private set; } + + public SharingDomainRestrictionModes SharingDomainRestrictionMode { get; private set; } + public string SharingAllowedDomainList { get; private set; } + public string SharingBlockedDomainList { get; private set; } + public string Status { get; private set; } + public int OwnersCount { get; private set; } + public long StorageUsed { get; private set; } + + internal SPConsumingTenantContainerByIdentity(SPContainerProperties spContainerProperties) + { + ContainerId = spContainerProperties.ContainerId; + ContainerName = spContainerProperties.ContainerName; + CreatedOn = spContainerProperties.CreatedOn; + Status = spContainerProperties.Status; + SensitivityLabel = spContainerProperties.SensitivityLabel; + OwnersCount = spContainerProperties.OwnersCount; + _ = spContainerProperties.StorageUsed; + int digits = 2; + double value = BytesToGB(spContainerProperties.StorageUsed); + value = Math.Round(value, digits); + StorageUsed = spContainerProperties.StorageUsed; + } + + private static double BytesToGB(long value) + { + double num = 1073741824.0; + return (double)value / num; + } + } +}