Public/Set-PrismOva.ps1

function Set-PrismOva {
    <#
    .SYNOPSIS
        Updates an OVA.
 
    .DESCRIPTION
        Updates the OVA with the given external identifier.
 
        This is a conditional operation: the v4 API requires the current ETag of the
        OVA (supplied as an If-Match header). When -ETag is not provided this function
        first performs a GET to obtain it. It is always recommended to perform a GET
        before an update so the correct ETag is used.
 
    .NOTES
        Implements:
          PUT /vmm/v{ApiVersion}/content/ovas/{extId} (operationId: updateOvaById)
 
        Uses the selected session's ApiVersion for the endpoint.
 
        The body must conform to the vmm.v4.2.content.Ova schema.
 
    .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 OVA to update.
 
    .PARAMETER Ova
        The updated OVA specification (hashtable or object).
 
    .PARAMETER ETag
        The current ETag of the OVA. When omitted it is retrieved automatically.
 
    .EXAMPLE
        $ova = (Get-PrismOva -ExtId $id).data
        $ova.name = 'RenamedOVA'
        Set-PrismOva -ExtId $id -Ova $ova
 
    .OUTPUTS
        A PrismTask reference describing the asynchronous update task.
    #>


    [CmdletBinding(SupportsShouldProcess = $true)]
    [OutputType([PrismTask])]
    param(
        [Parameter(Mandatory = $false,
            HelpMessage = 'Prism Session Name')][string]$PrismSession,

        [Parameter(Mandatory = $true,
            ValueFromPipelineByPropertyName = $true,
            HelpMessage = 'OVA external identifier (UUID)')]
        [Alias('Id', 'OvaExtId')][string]$ExtId,

        [Parameter(Mandatory = $true,
            ValueFromPipeline = $true,
            HelpMessage = 'Updated OVA specification')]
        [Alias('Body', 'Spec')][psobject]$Ova,

        [Parameter(Mandatory = $false)][string]$ETag
    )

    process {
        if (-not $PSCmdlet.ShouldProcess($ExtId, 'Update OVA')) { return }

        $PrismSessionConfig = Get-PrismSession $PrismSession
        $ovaPath = 'vmm/v{0}/content/ovas/{1}' -f $PrismSessionConfig.ApiVersion, $ExtId

        if (-not $ETag) {
            $ETag = Get-PrismResourceEtag -PrismSession $PrismSession -Path $ovaPath
        }

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

        $RequestSplat = @{
            PrismSession = $PrismSession
            Method       = 'PUT'
            Path         = $ovaPath
            Header       = $headers
            Body         = $Ova
        }
        $Response = Invoke-PrismRequest @RequestSplat
        return [PrismTask]::new($Response.data, $PrismSessionConfig.Name)
    }
}