PowerCLI-Example-Scripts icon indicating copy to clipboard operation
PowerCLI-Example-Scripts copied to clipboard

New-HVPool: Errors when source JSON file has null values for maxNumberOfMonitors and maxResolutionOfAnyOneMonitor

Open chriskoch99 opened this issue 3 years ago • 3 comments

Scenario: Exporting pool settings from a desktop pool in one pod, for use in creating a replica pool in another pod.

Source pool is Automated, Instant Clone, Blast protocol only. No PCoIP.

Exported JSON file has the following:

 "PcoipDisplaySettings":  {
                                                                                         "Renderer3D":  "MANAGE_BY_VSPHERE_CLIENT",
                                                                                         "EnableGRIDvGPUs":  false,
                                                                                         "VGPUGridProfile":  null,
                                                                                         "VRamSizeMB":  null,
                                                                                         "VRamSizeKB":  null,
                                                                                         "MaxNumberOfMonitors":  null,
                                                                                         "MaxResolutionOfAnyOneMonitor":  null
                                                                                     }

Using New-HVPool with the JSON file as input for the -spec option, I get the following:

The variable cannot be validated because the value 0 is not a valid value for the maxNumberOfMonitors variable.
At C:\Users\chriskoch99\Documents\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.HV.Helper.psm1:4536 char:17
+ ...             $maxNumberOfMonitors = $jsonObject.DesktopSettings.displa ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [], ValidationMetadataException
    + FullyQualifiedErrorId : ValidateSetFailure
 
The variable cannot be validated because the value  is not a valid value for the maxResolutionOfAnyOneMonitor variable.
At C:\Users\chriskoch99\Documents\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.HV.Helper.psm1:4537 char:17
+ ...             $maxResolutionOfAnyOneMonitor = $jsonObject.DesktopSettin ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (:) [], ValidationMetadataException
    + FullyQualifiedErrorId : ValidateSetFailure

This is because null values are not included in the ValidateSet for the $maxNumberOfMonitors and $maxResolutionOfAnyOneMonitor variables as defined at the beginning of the script, and the if ($null -ne $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings) section doesn't code around the possibility of null values for Blast-only pools.

To resolve this, I have modified the following:

                $maxNumberOfMonitors = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.maxNumberOfMonitors
                $maxResolutionOfAnyOneMonitor = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.maxResolutionOfAnyOneMonitor

to the following:

                If ($jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.maxNumberOfMonitors) {
				 $maxNumberOfMonitors = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.maxNumberOfMonitors
				}
                If ($jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.maxResolutionOfAnyOneMonitor) {
				 $maxResolutionOfAnyOneMonitor = $jsonObject.DesktopSettings.displayProtocolSettings.pcoipDisplaySettings.maxResolutionOfAnyOneMonitor
				}

This seems to work. For Blast only pools, the values of these settings when you export them will generally be null, and the function should allow for this.

Thoughts?

chriskoch99 avatar Aug 31 '21 22:08 chriskoch99