Public/Disable-DuneResourceAlerting.ps1

<#
.SYNOPSIS
Disable alerting for a Dune resource for a limited time.

.DESCRIPTION
Disables alerting on a Dune resource for the specified duration and returns a DuneJob object representing the operation. Specify the target either by resource Id or by passing a DuneResource object to the Resource parameter (ValueFromPipeline).

.PARAMETER Id
The GUID of the resource for which alerting should be disabled. Mandatory in the Id parameter set.

.PARAMETER Resource
A DuneResource object whose Id will be used to disable alerting. Mandatory in the Resource parameter set and accepts pipeline input.

.PARAMETER DurationMinutes
Number of minutes to disable alerting for. Required.

.PARAMETER Reason
A short textual reason for disabling alerting. Required.

.PARAMETER SendNotification
Switch indicating whether to send notifications about the alerting change.

.EXAMPLE
PS> Disable-DuneResourceAlerting -Id 3d8f6b5a-... -DurationMinutes 60 -Reason "Maintenance window"
Disables alerting for the resource with the specified Id for 60 minutes.

.EXAMPLE
PS> Get-DuneResource -Name "myvm" | Disable-DuneResourceAlerting -DurationMinutes 30 -Reason "Applying updates"
Pipeline example using the Resource parameter set to disable alerting for a resource object.

.EXAMPLE
PS> Disable-DuneResourceAlerting -Id 3d8f6b5a-... -DurationMinutes 15 -Reason "Quick fix" -SendNotification
Disables alerting and sends a notification about the action.
#>

function Disable-DuneResourceAlerting {
    [CmdletBinding(DefaultParameterSetName='Default')]
    param (
        [Parameter(Mandatory, ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(Mandatory, ParameterSetName = "Resource", ValueFromPipeline)]
        [DuneResource]$Resource,

        [Parameter(Mandatory)]
        [int]$DurationMinutes,

        [Parameter(Mandatory)]
        [string]$Reason,

        [Parameter()]
        [switch]$SendNotification
    )

    begin {}

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"
        if ($Resource) { $Id = $Resource.Id }
        $Url = "resources/$($Id)/disablealerting"
        $Body = @{
            DurationMinutes  = $DurationMinutes
            Reason           = $Reason
            SendNotification = $SendNotification
        }
        $Return = Invoke-DuneApiRequest $Url -Method POST -Body $Body
        $ReturnObject = if ($Return.Content) { $Return.Content | ConvertFrom-Json | ConvertTo-DuneClassObject -Class DuneJob }
        return $ReturnObject
    }

    end {}
}