Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature: added filter condition to Get-PnPAzureADApp #2477

Merged
merged 2 commits into from
Oct 18, 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 @@ -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. [#2477](https://github.com/pnp/powershell/pull/2477)

### Changed

Expand Down
23 changes: 22 additions & 1 deletion documentation/Get-PnPAzureADApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ 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
Specify the display name, id or app id.

```yaml
Type: AzureADAppPipeBind
Parameter Sets: (All)
Parameter Sets: Identity
Aliases:

Required: False
Expand All @@ -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)
4 changes: 2 additions & 2 deletions documentation/Get-PnPTeamsTeam.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
25 changes: 20 additions & 5 deletions src/Commands/AzureAD/GetAzureADApp.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)))
Expand All @@ -24,8 +29,18 @@ protected override void ExecuteCmdlet()
}
else
{
List<AzureADApp> apps = new List<AzureADApp>();
var result = GraphHelper.GetResultCollectionAsync<AzureADApp>(Connection, "/v1.0/applications", AccessToken).GetAwaiter().GetResult();
Dictionary<string, string> additionalHeaders = null;
string requestUrl = "/v1.0/applications";
if (!string.IsNullOrEmpty(Filter))
{
requestUrl = $"{requestUrl}?$filter=({Filter})";

additionalHeaders = new Dictionary<string, string>
{
{ "ConsistencyLevel", "eventual" }
};
}
var result = GraphHelper.GetResultCollectionAsync<AzureADApp>(Connection, requestUrl, AccessToken, additionalHeaders: additionalHeaders).GetAwaiter().GetResult();
WriteObject(result, true);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/Commands/Teams/GetTeamsTeam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@

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;

/// <summary>
/// Filter supports whatever you can pass to $filter.
/// 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
/// </summary>
[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_Filter)]
public string Filter = null;

protected override void ExecuteCmdlet()
Expand Down