From 7456ca8d8c3875e14eaa77353b09cc1127c0a090 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Fri, 6 Sep 2024 17:03:20 +0200 Subject: [PATCH 1/2] Fixing Get-PnPFlow not working without -AsAdmin --- CHANGELOG.md | 1 + src/Commands/Base/PnPConnectedCmdlet.cs | 2 +- src/Commands/Base/TokenHandler.cs | 2 +- src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs | 4 +++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f4c96e16..00c91a454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fix issue with Power Platform cmdlets not working correctly in non-commercial cloud environments. - Fix issue with `Get-PnPFlow` not working correctly when `-AsAdmin` parameter is specified due to API changes. - Fix `Connect-PnPOnline` not returning correct `ClientId` in the connection object. +- Fixed `Get-PnPFlow` not working without `-AsAdmin` ### Removed diff --git a/src/Commands/Base/PnPConnectedCmdlet.cs b/src/Commands/Base/PnPConnectedCmdlet.cs index 363881e02..6dfaf093e 100644 --- a/src/Commands/Base/PnPConnectedCmdlet.cs +++ b/src/Commands/Base/PnPConnectedCmdlet.cs @@ -63,7 +63,7 @@ protected override void ProcessRecord() switch (ex) { case Model.Graph.GraphException gex: - errorMessage = $"{gex.HttpResponse.ReasonPhrase} ({(int)gex.HttpResponse.StatusCode}): {gex.Error.Message}"; + errorMessage = $"{gex.HttpResponse.ReasonPhrase} ({(int)gex.HttpResponse.StatusCode}): {(gex.Error != null ? gex.Error.Message : gex.HttpResponse.Content.ReadAsStringAsync().Result)}"; break; case Core.SharePointRestServiceException rex: diff --git a/src/Commands/Base/TokenHandler.cs b/src/Commands/Base/TokenHandler.cs index 9a4206f06..e845498f0 100644 --- a/src/Commands/Base/TokenHandler.cs +++ b/src/Commands/Base/TokenHandler.cs @@ -193,7 +193,7 @@ internal static string GetAccessToken(Cmdlet cmdlet, string audience, PnPConnect } if (!permissionsInPlace) { - cmdlet.WriteVerbose($"The currect access token might not have the required permissions to execute this cmdlet. Required are one or more of the following: {string.Join(", ", permissionEvaluations.Select(p => p.MissingPermissions))}"); + cmdlet.WriteVerbose($"The currect access token might not have the required permissions to execute this cmdlet. Required are one or more of the following: {string.Join(", ", permissionEvaluations.Select(p => string.Join(", ", p.MissingPermissions)))}"); } return accessToken; diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs index 2669eeb5c..9e53b76f0 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlow.cs @@ -81,7 +81,9 @@ protected override void ExecuteCmdlet() WriteVerbose($"Retrieving all Power Automate Flows within environment '{environmentName}'{(filter != null ? $" with filter '{filter}'" : "")}"); - var flows = GraphHelper.GetResultCollection(this, Connection, baseUrl + $"/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/v2/flows?api-version=2016-11-01{(filter != null ? $"&$filter={filter}" : "")}", AccessToken); + var flowUrl = $"{baseUrl}/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/{(AsAdmin ? "v2" : "")}/flows?api-version=2016-11-01{(filter != null ? $"&$filter={filter}" : "")}"; + var flows = GraphHelper.GetResultCollection(this, Connection, flowUrl, AccessToken); + WriteObject(flows, true); } From 0c8cec5a0cf05e535704b71e4e6d6912aab79ee8 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Fri, 6 Sep 2024 17:04:16 +0200 Subject: [PATCH 2/2] Added PR reference --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00c91a454..8fff5674b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,8 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fix issue with Power Platform cmdlets not working correctly in non-commercial cloud environments. - Fix issue with `Get-PnPFlow` not working correctly when `-AsAdmin` parameter is specified due to API changes. - Fix `Connect-PnPOnline` not returning correct `ClientId` in the connection object. -- Fixed `Get-PnPFlow` not working without `-AsAdmin` - +- Fixed `Get-PnPFlow` not working without `-AsAdmin` [#4244](https://github.com/pnp/powershell/pull/4244) ### Removed ### Contributors