Public/Remove-PrismCategory.ps1

function Remove-PrismCategory {
    <#
    .SYNOPSIS
        Deletes a Category.
 
    .DESCRIPTION
        Deletes the Category with the given external identifier. This will fail if the
        Category is still associated with any entity.
 
    .NOTES
        Implements:
          DELETE /prism/v{ApiVersion}/config/categories/{extId} (operationId: deleteCategoryById)
 
        Uses the selected session's ApiVersion for the endpoint.
 
    .PARAMETER PrismSession
        The server/FQDN of the PrismSession to use. May be omitted when only one session exists.
 
    .PARAMETER ExtId
        The external identifier (UUID) of the Category to delete.
 
    .PARAMETER Category
        A PrismCategory to delete, supplied explicitly or through the pipeline.
        Uses its ExtId and session unless -PrismSession is supplied.
 
    .EXAMPLE
        Remove-PrismCategory -ExtId '4c41eafe-82cc-44b3-93ff-cb5c6cf40150'
 
    .OUTPUTS
        None.
    #>


    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High', DefaultParameterSetName = 'ByCategory')]
    param(
        [Parameter(Mandatory = $false,
            HelpMessage = 'Prism Session Name')][string]$PrismSession,

        [Parameter(Mandatory = $true,
            ParameterSetName = 'ById',
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = 'Category external identifier (UUID)')]
        [Alias('Id', 'CategoryExtId')][ValidateNotNullOrEmpty()][string]$ExtId,

        [Parameter(Mandatory = $true, ParameterSetName = 'ByCategory', ValueFromPipeline = $true)]
        [ValidateNotNull()][PrismCategory]$Category
    )

    process {
        $categoryId = if ($PSCmdlet.ParameterSetName -eq 'ByCategory') { $Category.ExtId } else { $ExtId }
        if ([string]::IsNullOrWhiteSpace($categoryId)) { throw 'A Category ExtId is required.' }
        if (-not $PSCmdlet.ShouldProcess($categoryId, 'Delete Category')) { return }

        $sessionName = if ($PSCmdlet.ParameterSetName -eq 'ByCategory' -and -not $PSBoundParameters.ContainsKey('PrismSession')) {
            $Category.PrismSession
        } else { $PrismSession }
        $PrismSessionConfig = Get-PrismSession $sessionName

        $headers = @{ 'NTNX-Request-Id' = (New-Guid).Guid }

        $RequestSplat = @{
            PrismSession = $PrismSessionConfig.Name
            Method       = 'DELETE'
            Path         = ('prism/v{0}/config/categories/{1}' -f $PrismSessionConfig.ApiVersion, $categoryId)
            Header       = $headers
        }
        $null = Invoke-PrismRequest @RequestSplat
    }
}