Public/Set-DuneAction.ps1

<#
.SYNOPSIS
Update an action.
 
.DESCRIPTION
Sends a PUT request to update action properties such as `IsDisabled`. Accepts an action object via pipeline or by ID.
 
.PARAMETER Action
A `DuneAction` object to update. Accepts pipeline input.
 
.PARAMETER Id
The GUID of the action to update.
 
.PARAMETER IsDisabled
Set to `$true` to disable the action, `$false` to enable it.
 
.EXAMPLE
PS> Set-DuneAction -Id 3d8f6b5a-... -IsDisabled $true
Disables the specified action.
 
.EXAMPLE
PS> Get-DuneAction -Name "backup" | Set-DuneAction -IsDisabled $false
Enables an action via pipeline.
#>

function Set-DuneAction {
    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline, ParameterSetName = "Object")]
        [DuneAction]$Action,

        [Parameter(ParameterSetName='Id')]
        [guid]$Id,

        [Parameter()]
        [bool]$IsDisabled
    )

    begin {}

    process {
        if ($Action) { $Id = $Action.Id }
        $Body = @{}
        if ($PSBoundParameters.ContainsKey('IsDisabled')) { $Body.IsDisabled = $IsDisabled }
        if (-not $Body.Keys) { Throw 'No properties specified to update.' }

        $Uri = "actions/$Id"
        $null = Invoke-DuneApiRequest -Uri $Uri -Method 'PUT' -Body $Body
    }

    end {}
}