diff --git a/documentation/Stop-PnPFlowRun.md b/documentation/Stop-PnPFlowRun.md new file mode 100644 index 000000000..b9f16e7e2 --- /dev/null +++ b/documentation/Stop-PnPFlowRun.md @@ -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 -Flow -Identity [-Force] [] +``` + +## 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) + diff --git a/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs b/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs new file mode 100644 index 000000000..29c7411fa --- /dev/null +++ b/src/Commands/PowerPlatform/PowerAutomate/StopFlowRun.cs @@ -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(); + } + } + } +}