From 49f9d515da71436b6846560b633d4e24dfd7e189 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Tue, 18 Oct 2022 13:11:54 +0300 Subject: [PATCH 1/2] Feature: added filter condition to Get-PnPAzureADApp --- CHANGELOG.md | 1 + documentation/Get-PnPAzureADApp.md | 23 ++++++++++++++++++++++- documentation/Get-PnPTeamsTeam.md | 4 ++-- src/Commands/AzureAD/GetAzureADApp.cs | 25 ++++++++++++++++++++----- src/Commands/Teams/GetTeamsTeam.cs | 9 ++++++--- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98c43fd87..bdcf44ec3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-Filter` parameter to `Get-PnPTeamsTeam` cmdlet to retrieve specific teams based on filter conditions. It supports simple and advanced queries. [#2467](https://github.com/pnp/powershell/pull/2467) , [#2474](https://github.com/pnp/powershell/pull/2474) - Added `Get-PnPMicrosoft365ExpiringGroup` cmdlet to retrieve Microsoft 365 groups which are nearing expiration.[#2466](https://github.com/pnp/powershell/pull/2466) - Added additional parameters to `Set-PnPContentType` cmdlet to support SPFx form customizer related properties.[#2456](https://github.com/pnp/powershell/pull/2456) +- Added `-Filter` parameter to `Get-PnPAzureADApp` cmdlet to retrieve specific Azure AD apps based on filter conditions. It suppports simple and advanced queries. ### Changed diff --git a/documentation/Get-PnPAzureADApp.md b/documentation/Get-PnPAzureADApp.md index b2e3209db..f73a42ae8 100644 --- a/documentation/Get-PnPAzureADApp.md +++ b/documentation/Get-PnPAzureADApp.md @@ -49,6 +49,13 @@ Get-PnPAzureADApp -Identity 93a9772d-d0af-4ed8-9821-17282b64690e This returns the Azure AD App registration with the app id specified or the id specified. +### Example 4 +```powershell +Get-PnPAzureADApp -Filter "startswith(description, 'contoso')" +``` + +This returns the Azure AD App registrations with the description starting with "contoso". This example demonstrates using Advanced Query capabilities (see: https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http#group-properties) + ## PARAMETERS ### -Identity @@ -56,7 +63,7 @@ Specify the display name, id or app id. ```yaml Type: AzureADAppPipeBind -Parameter Sets: (All) +Parameter Sets: Identity Aliases: Required: False @@ -66,6 +73,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Filter +Specify the query to pass to Graph API in $filter. + +```yaml +Type: String +Parameter Sets: Filter + +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/documentation/Get-PnPTeamsTeam.md b/documentation/Get-PnPTeamsTeam.md index 647026214..81fa1a415 100644 --- a/documentation/Get-PnPTeamsTeam.md +++ b/documentation/Get-PnPTeamsTeam.md @@ -71,7 +71,7 @@ Specify the group id, mailNickname or display name of the team to use. ```yaml Type: TeamsTeamPipeBind -Parameter Sets: (All) +Parameter Sets: Identity Required: False Position: Named @@ -85,7 +85,7 @@ Specify the query to pass to Graph API in $filter. ```yaml Type: String -Parameter Sets: (All) +Parameter Sets: Filter Required: False Position: Named diff --git a/src/Commands/AzureAD/GetAzureADApp.cs b/src/Commands/AzureAD/GetAzureADApp.cs index 03e5076bd..26c86f2b1 100644 --- a/src/Commands/AzureAD/GetAzureADApp.cs +++ b/src/Commands/AzureAD/GetAzureADApp.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using System.Management.Automation; using PnP.PowerShell.Commands.Attributes; using PnP.PowerShell.Commands.Base; @@ -9,13 +8,19 @@ namespace PnP.PowerShell.Commands.AzureAD { - [Cmdlet(VerbsCommon.Get, "PnPAzureADApp")] + [Cmdlet(VerbsCommon.Get, "PnPAzureADApp", DefaultParameterSetName = ParameterSet_Identity)] [RequiredMinimalApiPermissions("Application.Read.All")] public class GetAzureADApp : PnPGraphCmdlet { - [Parameter(Mandatory = false)] + private const string ParameterSet_Identity = "Identity"; + private const string ParameterSet_Filter = "Filter"; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_Identity)] public AzureADAppPipeBind Identity; + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_Filter)] + public string Filter = null; + protected override void ExecuteCmdlet() { if (ParameterSpecified(nameof(Identity))) @@ -24,8 +29,18 @@ protected override void ExecuteCmdlet() } else { - List apps = new List(); - var result = GraphHelper.GetResultCollectionAsync(Connection, "/v1.0/applications", AccessToken).GetAwaiter().GetResult(); + Dictionary additionalHeaders = null; + string requestUrl = "/v1.0/applications"; + if (!string.IsNullOrEmpty(Filter)) + { + requestUrl = $"{requestUrl}?$filter=({Filter})"; + + additionalHeaders = new Dictionary + { + { "ConsistencyLevel", "eventual" } + }; + } + var result = GraphHelper.GetResultCollectionAsync(Connection, requestUrl, AccessToken, additionalHeaders: additionalHeaders).GetAwaiter().GetResult(); WriteObject(result, true); } } diff --git a/src/Commands/Teams/GetTeamsTeam.cs b/src/Commands/Teams/GetTeamsTeam.cs index bf7129ffb..2462bb72f 100644 --- a/src/Commands/Teams/GetTeamsTeam.cs +++ b/src/Commands/Teams/GetTeamsTeam.cs @@ -6,11 +6,14 @@ namespace PnP.PowerShell.Commands.Graph { - [Cmdlet(VerbsCommon.Get, "PnPTeamsTeam")] + [Cmdlet(VerbsCommon.Get, "PnPTeamsTeam", DefaultParameterSetName = ParameterSet_Identity)] [RequiredMinimalApiPermissions("Group.Read.All")] public class GetTeamsTeam : PnPGraphCmdlet { - [Parameter(Mandatory = false)] + private const string ParameterSet_Identity = "Identity"; + private const string ParameterSet_Filter = "Filter"; + + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_Identity)] public TeamsTeamPipeBind Identity; /// @@ -18,7 +21,7 @@ public class GetTeamsTeam : PnPGraphCmdlet /// For details on which operators are supported for which properties, see this: /// https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http#group-properties /// - [Parameter(Mandatory = false)] + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_Filter)] public string Filter = null; protected override void ExecuteCmdlet() From e87212ea83fed1a6cac86cd424e9b05ee44aea63 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Tue, 18 Oct 2022 13:13:42 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdcf44ec3..1007bfc61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-Filter` parameter to `Get-PnPTeamsTeam` cmdlet to retrieve specific teams based on filter conditions. It supports simple and advanced queries. [#2467](https://github.com/pnp/powershell/pull/2467) , [#2474](https://github.com/pnp/powershell/pull/2474) - Added `Get-PnPMicrosoft365ExpiringGroup` cmdlet to retrieve Microsoft 365 groups which are nearing expiration.[#2466](https://github.com/pnp/powershell/pull/2466) - Added additional parameters to `Set-PnPContentType` cmdlet to support SPFx form customizer related properties.[#2456](https://github.com/pnp/powershell/pull/2456) -- Added `-Filter` parameter to `Get-PnPAzureADApp` cmdlet to retrieve specific Azure AD apps based on filter conditions. It suppports simple and advanced queries. +- Added `-Filter` parameter to `Get-PnPAzureADApp` cmdlet to retrieve specific Azure AD apps based on filter conditions. It suppports simple and advanced queries. [#2477](https://github.com/pnp/powershell/pull/2477) ### Changed