Public/Remove-DunePatchingWindow.ps1

<#
.SYNOPSIS
Remove a patching window.

.DESCRIPTION
Deletes a patching window identified by `Name`, `Id`, or by passing a `DunePatchingWindow` object via pipeline. Observes `ShouldProcess`.

.PARAMETER Name
The name of the patching window to remove. Use the `Name` parameter set.

.PARAMETER Id
The GUID of the patching window to remove. Use the `Id` parameter set.

.PARAMETER PatchingWindow
A `DunePatchingWindow` object; pipeline input supported to identify the patching window.

.EXAMPLE
PS> Remove-DunePatchingWindow -Name "monthly-maintenance"
Removes the patching window with the specified name.

.EXAMPLE
PS> Get-DunePatchingWindow -Name "monthly-maintenance" | Remove-DunePatchingWindow
Pipeline example removing a patching window.
#>

function Remove-DunePatchingWindow {
    [CmdletBinding(SupportsShouldProcess)]
    param (
        [Parameter(Mandatory, ParameterSetName = "Name", Position = 0)]
        [string]$Name,

        [Parameter(Mandatory, ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(Mandatory, ParameterSetName = "PatchingWindow", ValueFromPipeline)]
        [DunePatchingWindow]$PatchingWindow
    )

    begin {
        Write-Debug "$($MyInvocation.MyCommand)|begin"
        $BaseUri = "patching/windows"
    }

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process"
        switch ($PSCmdlet.ParameterSetName) {
            'Name' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Name)"
                $PatchingWindow = Get-DunePatchingWindow -Name $Name
            }
            'Id' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Id)"
                $PatchingWindow = Get-DunePatchingWindow -Id $Id
            }
            'PatchingWindow' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($PatchingWindow.Id)"
            }
            Default {
                return
            }
        }
        $Uri = $BaseUri, $PatchingWindow.Id -join "/"

        if ($PSCmdlet.ShouldProcess($PatchingWindow.Name)) {
            $Null = Invoke-DuneApiRequest $Uri -Method DELETE
        }
    }

    end {}
}