Public/Remove-DuneDeploymentTemplate.ps1

<#
.SYNOPSIS
Remove a deployment template.

.DESCRIPTION
Deletes a `DuneDeploymentTemplate` by `Id` or by passing a `DuneDeploymentTemplate` object via pipeline. The cmdlet supports `ShouldProcess` and will prompt for confirmation depending on the caller's confirmation preferences.

.PARAMETER Id
The GUID Id of the deployment template to remove.

.PARAMETER DeploymentTemplate
A `DuneDeploymentTemplate` object from the pipeline.

.EXAMPLE
PS> Remove-DuneDeploymentTemplate -Id 3d8f6b5a-...
Removes the deployment template with the specified Id after confirmation.

.EXAMPLE
PS> Get-DuneDeploymentTemplate -Name "webapp" | Remove-DuneDeploymentTemplate
Pipeline example removing a template object returned from Get-DuneDeploymentTemplate.
#>

function Remove-DuneDeploymentTemplate {
    [CmdletBinding(
        SupportsShouldProcess,
        ConfirmImpact = 'High',
        DefaultParameterSetName = 'Id'
    )]
    param (
        [Parameter(Mandatory, ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(Mandatory, ParameterSetName = "DeploymentTemplate", ValueFromPipeline)]
        [DuneDeploymentTemplate]$DeploymentTemplate
    )

    begin {
        Write-Debug "$($MyInvocation.MyCommand)|begin"
        $Uri = "deploymenttemplates"
    }

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"
        switch ($PSCmdlet.ParameterSetName) {
            'Id' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Id)"
                $DeploymentTemplate = Get-DuneDeploymentTemplate -Id $Id
            }
            'DeploymentTemplate' {
                Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($DeploymentTemplate.Id)"
            }
            Default {
                return
            }
        }
        $Url = $("{0}/{1}" -f $Uri, $DeploymentTemplate.Id)
        if ($PSCmdlet.ShouldProcess($DeploymentTemplate.Name)) {
            $Null = Invoke-DuneApiRequest $Url -Method DELETE
        }
    }

    end {
        Write-Debug "$($MyInvocation.MyCommand)|end"
    }
}