From a6d2a4c8104a5e2ebd451488681eba5878532469 Mon Sep 17 00:00:00 2001 From: Nishkalank Bezawada <47456098+NishkalankBezawada@users.noreply.github.com> Date: Mon, 31 Jul 2023 16:05:06 +0200 Subject: [PATCH 1/3] New Command - Get-PnPFlowOwners --- documentation/Get-PnPFlowOwners.md | 119 ++++++++++++++++++ .../PowerAutomate/FlowPermission.cs | 31 +++++ .../PowerAutomate/FlowPermissionPrincipal.cs | 21 ++++ .../PowerAutomate/FlowPermissionProperties.cs | 25 ++++ .../PowerAutomate/GetFlowOwners.cs | 39 ++++++ 5 files changed, 235 insertions(+) create mode 100644 documentation/Get-PnPFlowOwners.md create mode 100644 src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermission.cs create mode 100644 src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionPrincipal.cs create mode 100644 src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionProperties.cs create mode 100644 src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs diff --git a/documentation/Get-PnPFlowOwners.md b/documentation/Get-PnPFlowOwners.md new file mode 100644 index 000000000..ef63e5703 --- /dev/null +++ b/documentation/Get-PnPFlowOwners.md @@ -0,0 +1,119 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFlowOwners.html +external help file: PnP.PowerShell.dll-Help.xml +title: Get-PnPFlowOwners +--- + +# Get-PnPFlowOwners + +## SYNOPSIS + +**Required Permissions** + +* Azure: management.azure.com + +Returns the flows for a given environment + +## SYNTAX + +```powershell +Get-PnPFlowOwners [-Environment ] [-Identity ] [-AsAdmin] +[-Connection ] [-Verbose] +``` + +## DESCRIPTION +This cmdlet returns the flowowners for a given flow for a given environment. + +## EXAMPLES + +### Example 1 +```powershell +Get-PnPPowerPlatformEnvironment -Identity "MyOrganization (default)" | Get-PnPFlowOwners +[-Environment ] [-Identity ] [-AsAdmin] +``` +This returns all the owners of the given flow for a given Power Platform environment + + +## PARAMETERS + +### -Environment +The name of the Power Platform environment or an Environment object to retrieve the owners of the flow. + +```yaml +Type: PowerAutomateEnvironmentPipeBind +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: The default environment +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identity +The Name/Id of the flow to retrieve. + +```yaml +Type: PowerPlatformPipeBind +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsAdmin +If specified returns the owners of the given flow as admin. If not specified only the flows for the current user will be targeted, and returns the owners of the targetted flow. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Connection +Optional connection to be used by the cmdlet. +Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. + +```yaml +Type: PnPConnection +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Verbose +When provided, additional debug statements will be shown while executing the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) + +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/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermission.cs b/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermission.cs new file mode 100644 index 000000000..d2d76d0a8 --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermission.cs @@ -0,0 +1,31 @@ +using System.Text.Json.Serialization; + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate +{ + /// + /// Contains information of Microsoft Power Automate Flow owners + /// + public class FlowPermission + { + /// + /// Name of the Flow as its Flow GUID + /// + public string Name { get; set; } + + /// + /// Unique identifier of this Flow. + /// + public string Id { get; set; } + + /// + /// Type of object, typically Microsoft.ProcessSimple/environments/flows/permissions + /// + public string Type { get; set; } + + /// + /// Additional information on the Flow owners + /// + [JsonPropertyName("properties")] + public FlowPermissionProperties Properties { get; set; } + } +} \ No newline at end of file diff --git a/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionPrincipal.cs b/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionPrincipal.cs new file mode 100644 index 000000000..3c951d5a3 --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionPrincipal.cs @@ -0,0 +1,21 @@ + + +using System.Text.Json.Serialization; + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate +{ + public class FlowPermissionPrincipal + { + /// + /// Principal ID + /// + [JsonPropertyName("id")] + public string Id { get; set; } + + /// + /// Principal type + /// + [JsonPropertyName("type")] + public string Type { get; set; } + } +} \ No newline at end of file diff --git a/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionProperties.cs b/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionProperties.cs new file mode 100644 index 000000000..f3cf54725 --- /dev/null +++ b/src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionProperties.cs @@ -0,0 +1,25 @@ +using System.Text.Json.Serialization; + +namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate +{ + public class FlowPermissionProperties + { + /// + /// User role name. + /// + [JsonPropertyName("roleName")] + public string RoleName { get; set; } + + /// + /// Permission type of the user + /// + [JsonPropertyName("permissionType")] + public string PermissionType { get; set; } + + /// + /// User principal, Usually Id & Type + /// + [JsonPropertyName("principal")] + public FlowPermissionPrincipal Principal { get; set; } + } +} \ No newline at end of file diff --git a/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs new file mode 100644 index 000000000..76dd8cc13 --- /dev/null +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs @@ -0,0 +1,39 @@ +using PnP.PowerShell.Commands.Base; +using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate; +using PnP.PowerShell.Commands.Utilities.REST; +using System.Management.Automation; + +namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate +{ + [Cmdlet(VerbsCommon.Get, "PnPFlowOwners")] + public class GetFlowOwners : PnPAzureManagementApiCmdlet + { + [Parameter(Mandatory = true)] + public PowerPlatformEnvironmentPipeBind Environment; + + [Parameter(Mandatory = true)] + public PowerAutomateFlowPipeBind Identity; + + [Parameter(Mandatory = false)] + public SwitchParameter AsAdmin; + + protected override void ExecuteCmdlet() + { + var environmentName = Environment.GetName(); + if (string.IsNullOrEmpty(environmentName)) + { + throw new PSArgumentException("Environment not found."); + } + + var flowName = Identity.GetName(); + if (string.IsNullOrEmpty(flowName)) + { + throw new PSArgumentException("Flow not found."); + } + + var flowOwners = GraphHelper.GetResultCollectionAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/permissions?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); + WriteObject(flowOwners, true); + } + } +} From cb2bbfe97a67ba1d6937e7455e705a1b35f90c2c Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Sun, 3 Sep 2023 01:35:58 +0200 Subject: [PATCH 2/3] Code cleanup --- ...t-PnPFlowOwners.md => Get-PnPFlowOwner.md} | 46 ++++++------------- .../{GetFlowOwners.cs => GetFlowOwner.cs} | 10 ++-- 2 files changed, 19 insertions(+), 37 deletions(-) rename documentation/{Get-PnPFlowOwners.md => Get-PnPFlowOwner.md} (51%) rename src/Commands/PowerPlatform/PowerAutomate/{GetFlowOwners.cs => GetFlowOwner.cs} (85%) diff --git a/documentation/Get-PnPFlowOwners.md b/documentation/Get-PnPFlowOwner.md similarity index 51% rename from documentation/Get-PnPFlowOwners.md rename to documentation/Get-PnPFlowOwner.md index ef63e5703..a92a19d9f 100644 --- a/documentation/Get-PnPFlowOwners.md +++ b/documentation/Get-PnPFlowOwner.md @@ -2,12 +2,12 @@ Module Name: PnP.PowerShell schema: 2.0.0 applicable: SharePoint Online -online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFlowOwners.html +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFlowOwner.html external help file: PnP.PowerShell.dll-Help.xml -title: Get-PnPFlowOwners +title: Get-PnPFlowOwner --- -# Get-PnPFlowOwners +# Get-PnPFlowOwner ## SYNOPSIS @@ -15,32 +15,29 @@ title: Get-PnPFlowOwners * Azure: management.azure.com -Returns the flows for a given environment +Returns the owners of a Power Automate flow ## SYNTAX ```powershell -Get-PnPFlowOwners [-Environment ] [-Identity ] [-AsAdmin] -[-Connection ] [-Verbose] +Get-PnPFlowOwner -Environment -Identity [-AsAdmin] ``` ## DESCRIPTION -This cmdlet returns the flowowners for a given flow for a given environment. +This cmdlet returns the Power Automate flow owners for a given Power Automate Flow in a Power Platform environment. ## EXAMPLES ### Example 1 ```powershell -Get-PnPPowerPlatformEnvironment -Identity "MyOrganization (default)" | Get-PnPFlowOwners -[-Environment ] [-Identity ] [-AsAdmin] +Get-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity 33f78dac-7e93-45de-ab85-67cad0f6ee30 ``` -This returns all the owners of the given flow for a given Power Platform environment - +Returns all the owners of the Power Automate Flow with the provided identifier on the default Power Platform environment ## PARAMETERS ### -Environment -The name of the Power Platform environment or an Environment object to retrieve the owners of the flow. +The Power Platform environment that hosts the Power Automate Flow to retrieve the owners of. ```yaml Type: PowerAutomateEnvironmentPipeBind @@ -49,16 +46,16 @@ Aliases: Required: True Position: Named -Default value: The default environment +Default value: None Accept pipeline input: False Accept wildcard characters: False ``` ### -Identity -The Name/Id of the flow to retrieve. +The Name, Id or instance of the Power Automate Flow to retrieve the permissions of. ```yaml -Type: PowerPlatformPipeBind +Type: PowerAutomateFlowPipeBind Parameter Sets: (All) Aliases: @@ -70,7 +67,7 @@ Accept wildcard characters: False ``` ### -AsAdmin -If specified returns the owners of the given flow as admin. If not specified only the flows for the current user will be targeted, and returns the owners of the targetted flow. +If specified returns the owners of the given flow as admin. If not specified only the flows for the current user will be targeted, and returns the owners of the targeted flow. ```yaml Type: SwitchParameter @@ -85,8 +82,7 @@ Accept wildcard characters: False ``` ### -Connection -Optional connection to be used by the cmdlet. -Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. +Optional connection to be used by the cmdlet. Retrieve the value for this parameter by either specifying -ReturnConnection on Connect-PnPOnline or by executing Get-PnPConnection. ```yaml Type: PnPConnection @@ -100,20 +96,6 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -Verbose -When provided, additional debug statements will be shown while executing the cmdlet. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) - -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/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs similarity index 85% rename from src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs rename to src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs index 76dd8cc13..82f76842d 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwners.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs @@ -6,8 +6,8 @@ namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate { - [Cmdlet(VerbsCommon.Get, "PnPFlowOwners")] - public class GetFlowOwners : PnPAzureManagementApiCmdlet + [Cmdlet(VerbsCommon.Get, "PnPFlowOwner")] + public class GetFlowOwner : PnPAzureManagementApiCmdlet { [Parameter(Mandatory = true)] public PowerPlatformEnvironmentPipeBind Environment; @@ -23,17 +23,17 @@ protected override void ExecuteCmdlet() var environmentName = Environment.GetName(); if (string.IsNullOrEmpty(environmentName)) { - throw new PSArgumentException("Environment not found."); + throw new PSArgumentException("Environment not found.", nameof(Environment)); } var flowName = Identity.GetName(); if (string.IsNullOrEmpty(flowName)) { - throw new PSArgumentException("Flow not found."); + throw new PSArgumentException("Flow not found.", nameof(Identity)); } var flowOwners = GraphHelper.GetResultCollectionAsync(Connection, $"https://management.azure.com/providers/Microsoft.ProcessSimple{(AsAdmin ? "/scopes/admin" : "")}/environments/{environmentName}/flows/{flowName}/permissions?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult(); WriteObject(flowOwners, true); } } -} +} \ No newline at end of file From 92452828d02abc0dd189c7d0e69e77e29a405a15 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Sun, 3 Sep 2023 01:36:03 +0200 Subject: [PATCH 3/3] Adding changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a56b420..09b7c4bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-EnableAutoExpirationVersionTrim`, `-ExpireVersionsAfterDays`, `-MajorVersions`, `-MinorVersions`, `-InheritTenantVersionPolicySettings`, `-StartApplyVersionPolicySettingToExistingDocLibs` and `-CancelApplyVersionPolicySettingToExistingDocLibs` to `Set-PnPSite` to allow for time based version expiration on the site level [#3373](https://github.com/pnp/powershell/pull/3373) - Added `-ReduceTempTokenLifetimeEnabled`, `-ReduceTempTokenLifetimeValue`, `-ViewersCanCommentOnMediaDisabled`, `-AllowGuestUserShareToUsersNotInSiteCollection`, `-ConditionalAccessPolicyErrorHelpLink`, `-CustomizedExternalSharingServiceUrl`, `-IncludeAtAGlanceInShareEmails` and `-MassDeleteNotificationDisabled` to `Set-PnPTenant` [#3348](https://github.com/pnp/powershell/pull/3348) - Added `Add-PnPFlowOwner` and `Remove-PnPFlowOwner` cmdlets which allow granting or removing permissions to a Power Automate flow [#3343](https://github.com/pnp/powershell/pull/3343) +- Added `Get-PnPFlowOwner` cmdlet which allows retrieving the owners of a Power Automate flow [#3314](https://github.com/pnp/powershell/pull/3314) ### Fixed