Skip to content

Enable-Flow

PowerApps: Enables or disables a flow

#Requires -Version 5.1
#Requires -Modules Microsoft.PowerApps.PowerShell

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [pscredential]$PACredential,

    [Parameter(Mandatory = $true)]
    [string]$FlowName,

    [Parameter(Mandatory = $true)]
    [bool]$Enable,

    [string]$EnvironmentName,
    [string]$ApiVersion
)

Process {
    try {
        ConnectPowerApps4Creators -PAFCredential $PACredential

        $cmdArgs = @{
            ErrorAction = 'Stop'
            FlowName    = $FlowName
        }

        if ($PSBoundParameters.ContainsKey('EnvironmentName')) { $cmdArgs.Add('EnvironmentName', $EnvironmentName) }
        if ($PSBoundParameters.ContainsKey('ApiVersion')) { $cmdArgs.Add('ApiVersion', $ApiVersion) }

        if ($Enable) { Enable-Flow @cmdArgs -ErrorAction Stop }
        else { Disable-Flow @cmdArgs -ErrorAction Stop }

        $result = Get-Flow @cmdArgs -ErrorAction Stop | Select-Object DisplayName, FlowName, Enabled, EnvironmentName, LastModifiedTime

        if ($null -ne $result) {
            $result | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force
        }
    }
    catch { throw }
    finally { DisconnectPowerApps4Creators }
}

PowerApps credentials for authentication

Identifier of the flow (not display name)

Enable or disable the flow

Environment containing the flow

API version to call

An interactive directory of PowerShell scripts.