Public/Remove-DuneCollection.ps1
|
<# .SYNOPSIS Remove a Dune collection. .DESCRIPTION Deletes a `DuneCollection`. You can target the collection by `Name`, `Id`, or by passing a `DuneCollection` object from the pipeline. Use `-IncludeChildren` to remove child deployments first, and `-HardDelete` to force permanent deletion if supported. .PARAMETER Name The name of the collection to remove (Name parameter set). .PARAMETER Id The GUID Id of the collection to remove (Id parameter set). .PARAMETER Collection A `DuneCollection` object provided via pipeline (Collection parameter set). .PARAMETER IncludeChildren When specified, child deployments will be removed before deleting the collection. .PARAMETER HardDelete When specified, attempt a hard/permanent delete instead of a soft delete. .EXAMPLE PS> Remove-DuneCollection -Name "my-collection" -IncludeChildren Prompts and removes the collection named "my-collection" and its child deployments. .EXAMPLE PS> Get-DuneCollection -Id 3d8f6b5a-... | Remove-DuneCollection -HardDelete Pipeline example using the `Collection` parameter set to hard-delete a collection. #> function Remove-DuneCollection { [CmdletBinding( SupportsShouldProcess, DefaultParameterSetName = 'Id', ConfirmImpact = 'High' )] param ( [Parameter(Mandatory, ParameterSetName = "Name", Position = 0)] [string]$Name, [Parameter(Mandatory, ParameterSetName = "Id")] [guid]$Id, [Parameter(ParameterSetName = "Collection", ValueFromPipeline, Mandatory)] [DuneCollection]$Collection, [Parameter()] [switch]$IncludeChildren, [Parameter()] [switch]$HardDelete ) begin { Write-Debug "$($MyInvocation.MyCommand)|begin" $Uri = "collections" } process { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)" switch ($PSCmdlet.ParameterSetName) { 'Name' { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Name)" $Collection = Get-DuneCollection -Name $Name } 'Id' { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Id)" $Collection = Get-DuneCollection -Id $Id } 'Collection' { Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)|$($Collection.Id)" } Default { return } } $Url = $("{0}/{1}" -f $Uri, $Collection.Id) if ($PSCmdlet.ShouldProcess($Collection.Name)) { if ($IncludeChildren) { $Collection | Get-DuneDeployment | Remove-DuneDeployment -IncludeChildren } if ($HardDelete) { $Url = $Url, "HardDelete=1" -join "?" } $Null = Invoke-DuneApiRequest $Url -Method DELETE } } end { Write-Debug "$($MyInvocation.MyCommand)|end" } } |