Public/Get-PrismNgtSetting.ps1
|
function Get-PrismNgtSetting { <# .SYNOPSIS Gets the Nutanix Guest Tools settings of a VM. .DESCRIPTION Accepts a PrismVM object or its external identifier. Returns typed NGT settings, including guest status and the VM, session and ETag context. Uses the selected session's ApiVersion. .PARAMETER VM A PrismVM, supplied explicitly or through the pipeline. Uses its ExtId and originating session unless -PrismSession is specified. .PARAMETER ExtId The VM external identifier (UUID). .PARAMETER PrismSession The server/FQDN of the session. May be omitted when only one session exists. .EXAMPLE Get-PrismNgtSetting -ExtId $vmId -PrismSession 'pc.lab.local' .EXAMPLE Get-PrismVM -ExtId $vmId | Get-PrismNgtSetting .OUTPUTS PrismNgtSetting .NOTES GET /vmm/v{ApiVersion}/ahv/config/vms/{extId}/guest-tools #> [CmdletBinding(DefaultParameterSetName = 'ByVM')] [OutputType([PrismNgtSetting])] param( [Parameter(Mandatory, ParameterSetName = 'ById', Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [Alias('Id', 'VmExtId')] [ValidateNotNullOrEmpty()][string]$ExtId, [Parameter(Mandatory, ParameterSetName = 'ByVM', Position = 0, ValueFromPipeline)] [ValidateNotNull()][PrismVM]$VM, [Parameter()][string]$PrismSession ) process { $vmId = if ($PSCmdlet.ParameterSetName -eq 'ByVM') { $VM.ExtId } else { $ExtId } if ([string]::IsNullOrWhiteSpace($vmId)) { throw 'A VM ExtId is required.' } $sessionName = if ($PSCmdlet.ParameterSetName -eq 'ByVM' -and -not $PSBoundParameters.ContainsKey('PrismSession')) { $VM.PrismSession } else { $PrismSession } $sessionConfig = Get-PrismSession $sessionName $path = 'vmm/v{0}/ahv/config/vms/{1}/guest-tools' -f $sessionConfig.ApiVersion, $vmId $RequestSplat = @{ PrismSession = $sessionConfig.Name Method = 'GET' Path = $path PassThruResponse = $true } $response = Invoke-PrismRequest @RequestSplat $data = ($response.Content | ConvertFrom-Json -ErrorAction Stop).data $setting = [PrismNgtSetting]::new($data, $vmId, $sessionConfig.Name) $setting.ETag = @($response.Headers.ETag)[0] $setting } } |