Skip to content

Commit 65f61bb

Browse files
Add warning to Get-PnPFlow command about required permissions (#4474)
* Add warning to Get-PnPFlow command about required permissions * Added requiredApiDelegatedPermissions --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent 6bfa732 commit 65f61bb

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

documentation/Get-PnPFlow.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ title: Get-PnPFlow
1414
**Required Permissions**
1515

1616
* Azure: management.azure.com
17+
* Azure Service Management : user_impersonation
18+
* Dynamics CRM : user_impersonation
19+
* PowerApps Service : User
20+
* Link to Required permissions reference : https://pnp.github.io/powershell/articles/determinepermissions.html#help-i-cant-figure-out-which-permissions-i-need
1721

1822
Returns Power Automate Flows
1923

src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
using System.Management.Automation;
55
using PnP.PowerShell.Commands.Enums;
66
using PnP.PowerShell.Commands.Utilities;
7+
using PnP.PowerShell.Commands.Attributes;
8+
using System;
79

810
namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate
911
{
1012
[Cmdlet(VerbsCommon.Get, "PnPFlow", DefaultParameterSetName = ParameterSet_ALL)]
13+
[ApiNotAvailableUnderApplicationPermissions]
14+
[RequiredApiDelegatedPermissions("azure/user_impersonation")]
1115
public class GetFlow : PnPAzureManagementApiCmdlet
1216
{
1317
private const string ParameterSet_BYIDENTITY = "By Identity";
@@ -29,43 +33,50 @@ public class GetFlow : PnPAzureManagementApiCmdlet
2933

3034
protected override void ExecuteCmdlet()
3135
{
32-
var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name;
33-
string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment);
34-
35-
if (ParameterSpecified(nameof(Identity)))
36+
try
3637
{
37-
var flowName = Identity.GetName();
38-
39-
WriteVerbose($"Retrieving specific Power Automate Flow with the provided name '{flowName}' within the environment '{environmentName}'");
38+
var environmentName = ParameterSpecified(nameof(Environment)) ? Environment.GetName() : PowerPlatformUtility.GetDefaultEnvironment(this, Connection, Connection.AzureEnvironment, AccessToken)?.Name;
39+
string baseUrl = PowerPlatformUtility.GetPowerAutomateEndpoint(Connection.AzureEnvironment);
4040

41-
var result = GraphHelper.Get<Model.PowerPlatform.PowerAutomate.Flow>(this, Connection, baseUrl + $"/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken);
42-
WriteObject(result, false);
43-
}
44-
else
45-
{
46-
string filter = null;
47-
switch (SharingStatus)
41+
if (ParameterSpecified(nameof(Identity)))
4842
{
49-
case FlowSharingStatus.SharedWithMe:
50-
filter = "search('team')";
51-
break;
43+
var flowName = Identity.GetName();
5244

53-
case FlowSharingStatus.Personal:
54-
filter = "search('personal')";
55-
break;
45+
WriteVerbose($"Retrieving specific Power Automate Flow with the provided name '{flowName}' within the environment '{environmentName}'");
5646

57-
case FlowSharingStatus.All:
58-
filter = "search('team AND personal')";
59-
break;
47+
var result = GraphHelper.Get<Model.PowerPlatform.PowerAutomate.Flow>(this, Connection, baseUrl + $"/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}?api-version=2016-11-01", AccessToken);
48+
WriteObject(result, false);
6049
}
50+
else
51+
{
52+
string filter = null;
53+
switch (SharingStatus)
54+
{
55+
case FlowSharingStatus.SharedWithMe:
56+
filter = "search('team')";
57+
break;
58+
59+
case FlowSharingStatus.Personal:
60+
filter = "search('personal')";
61+
break;
6162

62-
WriteVerbose($"Retrieving all Power Automate Flows within environment '{environmentName}'{(filter != null ? $" with filter '{filter}'" : "")}");
63+
case FlowSharingStatus.All:
64+
filter = "search('team AND personal')";
65+
break;
66+
}
6367

64-
var flowUrl = $"{baseUrl}/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/{(AsAdmin ? "v2" : "")}/flows?api-version=2016-11-01{(filter != null ? $"&$filter={filter}" : "")}";
65-
var flows = GraphHelper.GetResultCollection<Model.PowerPlatform.PowerAutomate.Flow>(this, Connection, flowUrl, AccessToken);
66-
67-
WriteObject(flows, true);
68+
WriteVerbose($"Retrieving all Power Automate Flows within environment '{environmentName}'{(filter != null ? $" with filter '{filter}'" : "")}");
6869

70+
var flowUrl = $"{baseUrl}/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/{(AsAdmin ? "v2" : "")}/flows?api-version=2016-11-01{(filter != null ? $"&$filter={filter}" : "")}";
71+
var flows = GraphHelper.GetResultCollection<Model.PowerPlatform.PowerAutomate.Flow>(this, Connection, flowUrl, AccessToken);
72+
73+
WriteObject(flows, true);
74+
75+
}
76+
}
77+
catch (Exception e)
78+
{
79+
WriteError(new ErrorRecord(new Exception("Make sure you have granted access to Azure AD App to Interact with Power Platform, To help understand the required permissions visit https://pnp.github.io/powershell/articles/determinepermissions.html#help-i-cant-figure-out-which-permissions-i-need"), e.Message, ErrorCategory.AuthenticationError, null));
6980
}
7081
}
7182
}

0 commit comments

Comments
 (0)