Skip to content

Commit

Permalink
Implemented Stop-PnPFlowRun (#1838)
Browse files Browse the repository at this point in the history
  • Loading branch information
milanholemans committed May 11, 2022
1 parent cc0d4e8 commit c57d18d
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 0 deletions.
109 changes: 109 additions & 0 deletions documentation/Stop-PnPFlowRun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
Module Name: PnP.PowerShell
title: Stop-PnPFlowRun
schema: 2.0.0
applicable: SharePoint Online
external help file: PnP.PowerShell.dll-Help.xml
online version: https://pnp.github.io/powershell/cmdlets/Stop-PnPFlowRun.html
---

# Stop-PnPFlowRun

## SYNOPSIS
**Required Permissions**

* Azure: management.azure.com

Stops/cancels a specific run of a Microsoft flow.

## SYNTAX

```powershell
Stop-PnPFlowRun -Environment <PowerAutomateEnvironmentPipeBind> -Flow <PowerAutomateFlowPipeBind> -Identity <PowerAutomateFlowRunPipeBind> [-Force] [<CommonParameters>]
```

## DESCRIPTION
This cmdlet cancels a running Power Automate flow run.

## EXAMPLES

### Example 1
```powershell
$environment = Get-PnPPowerPlatformEnvironment
Stop-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230
```
This cancels the specified flow run of the specified flow


### Example 2
```powershell
$environment = Get-PnPPowerPlatformEnvironment
Stop-PnPFlowRun -Environment $environment -Flow fba63225-baf9-4d76-86a1-1b42c917a182 -Identity 08585531682024670884771461819CU230 -Force
```
This cancels the specified flow run of the specified flow without confirmation

## PARAMETERS

### -Environment
The name of the Power Platform environment or an Environment object to retrieve the available flows for.

```yaml
Type: PowerAutomateEnvironmentPipeBind
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Flow
The Name/Id of the flow to retrieve the available flow runs for.

```yaml
Type: PowerAutomateFlowPipeBind
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Identity
The Name/Id of the flow run to cancel.

```yaml
Type: PowerAutomateFlowRunPipeBind
Parameter Sets: (All)
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Force
Specifying the Force parameter will skip the confirmation question.

```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)

52 changes: 52 additions & 0 deletions src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using PnP.PowerShell.Commands.Attributes;
using PnP.PowerShell.Commands.Base;
using PnP.PowerShell.Commands.Base.PipeBinds;
using System.Management.Automation;
using PnP.PowerShell.Commands.Utilities.REST;
using Resources = PnP.PowerShell.Commands.Properties.Resources;

namespace PnP.PowerShell.Commands.PowerPlatform.PowerAutomate
{
[Cmdlet(VerbsLifecycle.Stop, "PnPFlowRun")]
[RequiredMinimalApiPermissions("https://management.azure.com/.default")]
public class StopFlowRun : PnPGraphCmdlet
{
[Parameter(Mandatory = true)]
public PowerPlatformEnvironmentPipeBind Environment;

[Parameter(Mandatory = true)]
public PowerAutomateFlowPipeBind Flow;

[Parameter(Mandatory = true)]
public PowerAutomateFlowRunPipeBind Identity;

[Parameter(Mandatory = false)]
public SwitchParameter Force;

protected override void ExecuteCmdlet()
{
var environmentName = Environment.GetName();
if (string.IsNullOrEmpty(environmentName))
{
throw new PSArgumentException("Environment not found.");
}

var flowName = Flow.GetName();
if (string.IsNullOrEmpty(flowName))
{
throw new PSArgumentException("Flow not found.");
}

var flowRunName = Identity.GetName();
if (string.IsNullOrEmpty(flowRunName))
{
throw new PSArgumentException("Flow run not found.");
}

if (Force || ShouldContinue($"Stop flow run with name '{flowRunName}'?", Resources.Confirm))
{
RestHelper.PostAsync(HttpClient, $"https://management.azure.com/providers/Microsoft.ProcessSimple/environments/{environmentName}/flows/{flowName}/runs/{flowRunName}/cancel?api-version=2016-11-01", AccessToken).GetAwaiter().GetResult();
}
}
}
}

0 comments on commit c57d18d

Please sign in to comment.