-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc0d4e8
commit c57d18d
Showing
2 changed files
with
161 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
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) | ||
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,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(); | ||
} | ||
} | ||
} | ||
} |