Private/Get-PrismResourceEtag.ps1

function Get-PrismResourceEtag {
    <#
    .SYNOPSIS
        Internal helper that retrieves the ETag for a Prism Central resource.
 
    .DESCRIPTION
        Many Nutanix Prism Central v4 mutating operations (power actions, PUT and
        PATCH) are conditional and require an If-Match header carrying the ETag that
        was returned by a prior GET of the resource. This helper performs that GET and
        returns the ETag value from the response headers so the caller can supply it
        as If-Match.
 
    .PARAMETER PrismSession
        The server/FQDN of the PrismSession to use. May be omitted when only one session exists.
 
    .PARAMETER Path
        The API path of the resource (relative to '/api/'), for example
        'vmm/v4.2/ahv/config/vms/{extId}'.
 
    .OUTPUTS
        [string] The ETag value, or $null when the resource did not return one.
    #>


    [CmdletBinding()]
    param(
        [Parameter()][string]$PrismSession,
        [Parameter(Mandatory)][string]$Path
    )

    $response = Invoke-PrismRequest -PrismSession $PrismSession -Path $Path -Method 'GET' -PassThruResponse

    ## Invoke-WebRequest exposes headers as string arrays; normalize to a single value.
    $etag = $response.Headers.ETag
    if ($etag -is [array]) { $etag = $etag[0] }

    if (-not $etag) {
        Write-Verbose "Get-PrismResourceEtag: No ETag header returned for [$Path]"
    }

    return $etag
}