Skip to content

Enable-Flow-Admin

PowerApps Admin: Enables or disables a flow

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

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

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

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

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

Process {
    try {
        ConnectPowerApps -PAFCredential $PACredential
        $args = @{ ErrorAction = 'Stop'; FlowName = $FlowName }
        if ($PSBoundParameters.ContainsKey('EnvironmentName')) { $args.Add('EnvironmentName', $EnvironmentName) }
        if ($PSBoundParameters.ContainsKey('ApiVersion')) { $args.Add('ApiVersion', $ApiVersion) }
        if ($Enable) { $null = Enable-AdminFlow @args -ErrorAction Stop }
        else { $null = Disable-AdminFlow @args -ErrorAction Stop }
        [PSCustomObject]@{ Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"; Status = "Success"; FlowName = $FlowName; Enabled = $Enable.ToString(); Message = "Flow '$FlowName' enabled status: $Enable" }
    }
    catch { throw }
    finally { DisconnectPowerApps }
}

PowerApps credentials

Flow name identifier

Enable or disable the flow

The flow's environment

API version to call

An interactive directory of PowerShell scripts.