Skip to content

Commit

Permalink
Merge pull request #3287 from NishkalankBezawada/Feature-3275
Browse files Browse the repository at this point in the history
Fixing Issue 3275 - Add SharingStatus to Get-PnPFlow
  • Loading branch information
KoenZomers authored Aug 6, 2023
2 parents b5da970 + 8b84d9a commit a261de8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `-Includes` option to `Get-PnPListItem` which allows for specifying additional fields to be retrieved. [#3270](https://github.com/pnp/powershell/pull/3270)
- Added `-AllowCommentsTextOnEmailEnabled` parameter to `Set-PnPTenant` which allows including the surrounding document context in email notification when user is mentioned in document comments. [#3268](https://github.com/pnp/powershell/pull/3268)
- Added `Export-PnPPowerApp` cmdlet which will export a specified PowerApp as zip package. [#2990](https://github.com/pnp/powershell/pull/2990)
- Added `AzureADLoginEndPoint` and `MicrosoftGraphEndPoint` parameters to `Connect-PnPOnline` cmdlet for use in custom Azure environments. [#2925](https://github.com/pnp/powershell/pull/2925)
- Added `-SharingStatus` parameter to `Get-PnPFlow` which allows for filtering flows based on their sharing status. [#3287](https://github.com/pnp/powershell/pull/3287)
- Added `-AzureADLoginEndPoint` and `-MicrosoftGraphEndPoint` parameters to `Connect-PnPOnline` cmdlet for use in custom Azure environments. [#2925](https://github.com/pnp/powershell/pull/2925)

### Fixed
Expand All @@ -31,6 +33,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Contributors

- Nishkalank Bezawada [NishkalankBezawada]
- [PowerBugi]
- Ganesh Sanap [ganesh-sanap]
- Siddharth Vaghasia [siddharth-vaghasia]
Expand Down
47 changes: 39 additions & 8 deletions documentation/Get-PnPFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,48 @@ title: Get-PnPFlow

* Azure: management.azure.com

Returns the flows for a given environment
Returns Power Automate Flows

## SYNTAX

### All (Default)
```powershell
Get-PnPFlow [-Environment <PowerAutomateEnvironmentPipeBind>] [-AsAdmin] [-Identity <PowerPlatformPipeBind>]
[-Connection <PnPConnection>] [-Verbose]
Get-PnPFlow [-Environment <PowerAutomateEnvironmentPipeBind>] [-AsAdmin] [-SharingStatus <FlowSharingStatus>] [-Connection <PnPConnection>] [-Verbose]
```

### By Identity
```powershell
Get-PnPFlow [-Environment <PowerAutomateEnvironmentPipeBind>] [-AsAdmin] [-Identity <PowerPlatformPipeBind>] [-Connection <PnPConnection>] [-Verbose]
```

## DESCRIPTION
This cmdlet returns the flows for a given environment.
This cmdlet returns Power Automate Flows meeting the specified criteria.

## EXAMPLES

### Example 1
```powershell
Get-PnPPowerPlatformEnvironment -Identity "MyOrganization (default)" | Get-PnPFlow
Get-PnPFlow -AsAdmin
```
This returns all the flows for a given Power Platform environment
Returns all the flows in the default Power Platform environment belonging to any user

### Example 2
```powershell
Get-PnPPowerPlatformEnvironment -Identity "MyOrganization (default)" | Get-PnPFlow
```
Returns all the flows for a given Power Platform environment belonging to the current user

### Example 3
```powershell
Get-PnPFlow -SharingStatus SharedWithMe
```
Returns all the flows which have been shared with the current user in the default Power Platform environment

### Example 4
```powershell
Get-PnPFlow -Identity fba63225-baf9-4d76-86a1-1b42c917a182
```
This returns a specific flow from the default environment
Returns a specific flow from the default Power Platform environment

## PARAMETERS

Expand All @@ -63,7 +80,7 @@ The Name/Id of the flow to retrieve.
```yaml
Type: PowerPlatformPipeBind
Parameter Sets: (All)
Parameter Sets: By Identity
Aliases:

Required: False
Expand Down Expand Up @@ -104,6 +121,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -SharingStatus
Allows specifying the type of Power Automate Flows that should be returned. Valid values: All, SharedWithMe, Personal.
```yaml
Type: FlowSharingStatus
Parameter Sets: All

Required: False
Position: Named
Default value: All
Accept pipeline input: False
Accept wildcard characters: False
```
### -Verbose
When provided, additional debug statements will be shown while executing the cmdlet.
Expand Down
23 changes: 23 additions & 0 deletions src/Commands/Enums/FlowSharingStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace PnP.PowerShell.Commands.Enums
{
/// <summary>
/// Scopes to which flow sharing status is defined
/// </summary>
public enum FlowSharingStatus
{
/// <summary>
/// returns flows that are shared with you, or created by you and shared with someone
/// </summary>
SharedWithMe,

/// <summary>
/// returns all flows created by you which are not shared.
/// </summary>
Personal,

/// <summary>
/// Combines personal and sharedwith me
/// </summary>
All
}
}
38 changes: 32 additions & 6 deletions src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@
using System;
using System.Linq;
using System.Management.Automation;
using PnP.PowerShell.Commands.Enums;

namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate
{
[Cmdlet(VerbsCommon.Get, "PnPFlow")]
[Cmdlet(VerbsCommon.Get, "PnPFlow", DefaultParameterSetName = ParameterSet_ALL)]
public class GetFlow : PnPAzureManagementApiCmdlet
{
[Parameter(Mandatory = false, ValueFromPipeline = true)]
private const string ParameterSet_BYIDENTITY = "By Identity";
private const string ParameterSet_ALL = "All";

[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_BYIDENTITY)]
[Parameter(Mandatory = false, ValueFromPipeline = true, ParameterSetName = ParameterSet_ALL)]
public PowerPlatformEnvironmentPipeBind Environment;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_BYIDENTITY)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALL)]
public SwitchParameter AsAdmin;

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_BYIDENTITY)]
public PowerAutomateFlowPipeBind Identity;

[Parameter(Mandatory = false, ParameterSetName = ParameterSet_ALL)]
public FlowSharingStatus SharingStatus = FlowSharingStatus.All;

protected override void ExecuteCmdlet()
{
string environmentName = null;
Expand Down Expand Up @@ -52,10 +61,27 @@ protected override void ExecuteCmdlet()
}
else
{
WriteVerbose($"Retrieving all Power Automate Flows within environment '{environmentName}'");
string filter = null;
switch (SharingStatus)
{
case FlowSharingStatus.SharedWithMe:
filter = "search('team')";
break;

case FlowSharingStatus.Personal:
filter = "search('personal')";
break;

var flows = GraphHelper.GetResultCollectionAsync<Model.PowerPlatform.PowerAutomate.Flow>(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult();
case FlowSharingStatus.All:
filter = "search('team AND personal')";
break;
}

WriteVerbose($"Retrieving all Power Automate Flows within environment '{environmentName}'{(filter != null ? $" with filter '{filter}'" : "")}");

var flows = GraphHelper.GetResultCollectionAsync<Model.PowerPlatform.PowerAutomate.Flow>(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows?api-version=2016-11-01{(filter != null ? $"&$filter={filter}" : "")}", AccessToken).GetAwaiter().GetResult();
WriteObject(flows, true);

}
}
}
Expand Down

0 comments on commit a261de8

Please sign in to comment.