vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
757 stars 603 forks source link

[VMware.Hv.Helper] A value of $false parameter "Value" on Set-HVGlobalSettings results in an error #496

Closed CajunBard closed 2 years ago

CajunBard commented 2 years ago

Filing this issue for tracking purposes. The cause has been identified, and a PR is in progress to provide a fix.

The below exception is logged when a $false value is passed via the -Value parameter of Set-HVGlobalSettings. This seems to be due to the way that we are checking that both -Key and -Value are set. The intent is that we want to check for the presence of both parameters, but the statement evaluates false since we are evaluating if they are both 'true' instead. See line 10281

PS> Set-HVGlobalSettings -Key 'generalData.hideDomainListInClient' -Value $false
Set-HVGlobalSettings : Both key:[generalData.hideDomainListInClient] and value:[False] needs to be specified
At line:1 char:1
+ Set-HVGlobalSettings -Key 'generalData.hideDomainListInClient' -Value ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorExeception
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Set-HVGlobalSettings

Upcoming PR will address this by changing the condition

from:

if ($key -and $value) {

to:

if ( $PSBoundParameters.ContainsKey('Key') -and $PSBoundParameters.ContainsKey('Value') ) {

kamennikolov commented 2 years ago

Fixed by https://github.com/vmware/PowerCLI-Example-Scripts/pull/497