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 diff --git a/documentation/Get-PnPFlowOwner.md b/documentation/Get-PnPFlowOwner.md new file mode 100644 index 000000000..a92a19d9f --- /dev/null +++ b/documentation/Get-PnPFlowOwner.md @@ -0,0 +1,101 @@ +--- +Module Name: PnP.PowerShell +schema: 2.0.0 +applicable: SharePoint Online +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPFlowOwner.html +external help file: PnP.PowerShell.dll-Help.xml +title: Get-PnPFlowOwner +--- + +# Get-PnPFlowOwner + +## SYNOPSIS + +**Required Permissions** + +* Azure: management.azure.com + +Returns the owners of a Power Automate flow + +## SYNTAX + +```powershell +Get-PnPFlowOwner -Environment -Identity [-AsAdmin] +``` + +## DESCRIPTION +This cmdlet returns the Power Automate flow owners for a given Power Automate Flow in a Power Platform environment. + +## EXAMPLES + +### Example 1 +```powershell +Get-PnPFlowOwner -Environment (Get-PnPPowerPlatformEnvironment -IsDefault) -Identity 33f78dac-7e93-45de-ab85-67cad0f6ee30 +``` +Returns all the owners of the Power Automate Flow with the provided identifier on the default Power Platform environment + +## PARAMETERS + +### -Environment +The Power Platform environment that hosts the Power Automate Flow to retrieve the owners of. + +```yaml +Type: PowerAutomateEnvironmentPipeBind +Parameter Sets: (All) +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identity +The Name, Id or instance of the Power Automate Flow to retrieve the permissions of. + +```yaml +Type: PowerAutomateFlowPipeBind +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 targeted 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 +``` + +## 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/GetFlowOwner.cs b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs new file mode 100644 index 000000000..82f76842d --- /dev/null +++ b/src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.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, "PnPFlowOwner")] + public class GetFlowOwner : 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.", nameof(Environment)); + } + + var flowName = Identity.GetName(); + if (string.IsNullOrEmpty(flowName)) + { + 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