Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Command - Get-PnPFlowOwners #3314

Merged
merged 3 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
101 changes: 101 additions & 0 deletions documentation/Get-PnPFlowOwner.md
Original file line number Diff line number Diff line change
@@ -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 <PowerAutomateEnvironmentPipeBind> -Identity <PowerAutomateFlowPipeBind> [-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)
31 changes: 31 additions & 0 deletions src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermission.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate
{
/// <summary>
/// Contains information of Microsoft Power Automate Flow owners
/// </summary>
public class FlowPermission
{
/// <summary>
/// Name of the Flow as its Flow GUID
/// </summary>
public string Name { get; set; }

/// <summary>
/// Unique identifier of this Flow.
/// </summary>
public string Id { get; set; }

/// <summary>
/// Type of object, typically Microsoft.ProcessSimple/environments/flows/permissions
/// </summary>
public string Type { get; set; }

/// <summary>
/// Additional information on the Flow owners
/// </summary>
[JsonPropertyName("properties")]
public FlowPermissionProperties Properties { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate
{
public class FlowPermissionPrincipal
{
/// <summary>
/// Principal ID
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
/// Principal type
/// </summary>
[JsonPropertyName("type")]
public string Type { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.PowerPlatform.PowerAutomate
{
public class FlowPermissionProperties
{
/// <summary>
/// User role name.
/// </summary>
[JsonPropertyName("roleName")]
public string RoleName { get; set; }

/// <summary>
/// Permission type of the user
/// </summary>
[JsonPropertyName("permissionType")]
public string PermissionType { get; set; }

/// <summary>
/// User principal, Usually Id & Type
/// </summary>
[JsonPropertyName("principal")]
public FlowPermissionPrincipal Principal { get; set; }
}
}
39 changes: 39 additions & 0 deletions src/Commands/PowerPlatform/PowerAutomate/GetFlowOwner.cs
Original file line number Diff line number Diff line change
@@ -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<FlowPermission>(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);
}
}
}
Loading