Public/Stop-DuneResourceGroup.ps1

<#
.SYNOPSIS
Stop resources in a resource group.

.DESCRIPTION
Requests the Dune API to stop resources belonging to a resource group. Identify the resource group by `Id` or pass a `DuneResourceGroup` object via pipeline. Use `TxId` for transaction correlation.

.PARAMETER Id
The GUID of the resource group. Use the `Id` parameter set.

.PARAMETER ResourceGroup
A `DuneResourceGroup` object; pipeline input supported to identify the resource group.

.PARAMETER TxId
Optional transaction id passed to the API. Defaults to a new GUID when not specified.

.EXAMPLE
PS> Stop-DuneResourceGroup -Id 3d8f6b5a-...
Stops resources within the specified resource group.

.EXAMPLE
PS> Get-DuneResourceGroup -Name "rg-prod" | Stop-DuneResourceGroup
Pipeline example using the `ResourceGroup` parameter set.
#>

function Stop-DuneResourceGroup {
    [CmdletBinding(DefaultParameterSetName = "Id")]
    param (
        [Parameter(ParameterSetName = "Id")]
        [guid]$Id,

        [Parameter(Mandatory, ParameterSetName = "ResourceGroup", ValueFromPipeline)]
        [DuneResourceGroup]$ResourceGroup,

        [Parameter()]
        [String]$TxId = (New-Guid)
    )

    begin {}

    process {
        Write-Debug "$($MyInvocation.MyCommand)|process|$($PSCmdlet.ParameterSetName)"
        if ($PSCmdlet.ParameterSetName -eq "ResourceGroup") {
            $Id = $ResourceGroup.Id
        }
        $Body = @{TxId = $TxId}
        $Null = Invoke-DuneApiRequest -Uri "resourcegroups/$($Id)/stopresources" -Method POST -Body $Body
    }

    end {}
}