-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3314 from NishkalankBezawada/GetFlowOwners
New Command - Get-PnPFlowOwners
- Loading branch information
Showing
6 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermission.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionPrincipal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Commands/Model/PowerPlatform/PowerAutomate/FlowPermissionProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |