vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
743 stars 601 forks source link

GlobalSettings.GlobalSettings_Update can't update displayPreLoginMessage (and other boolen properties) via function #607

Open Po-temkin opened 1 year ago

Po-temkin commented 1 year ago

Describe the bug

I'm in the process of writing a function that will update all properties of $services.GlobalSettings.GlobalSettings_Get().GeneralData. I know about that module VMware.Hv.Helper has Set-HVGlobalSettings cmdlet, but some new properties from Horizon 2212 aren't in it. One of the properties is displayPreLoginMessage. When I try to set this property via function, I see this:

Exception calling "GlobalSettings_Update" with "1" argument(s): "There is an error in the XML document."
At C:\Program Files\WindowsPowerShell\Modules\Potemkin.Hv.Helper\Potemkin.Hv.Helper.psm1:1271 char:5
+     $services.GlobalSettings.GlobalSettings_Update($updates)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidOperationException

I wrote a simple function to reproduce the error. You can find it below. Interesting that everything is OK if I execute:

Set-HVGlobalGeneralSettings -DisplayPreLoginMessage $true

This also works (if i run it directly in shell):

$updates = Get-MapEntry -Key 'generalData.displayPreLoginMessage' -Value $false
$services.GlobalSettings.GlobalSettings_Update($updates)

UPD: The same situation with DisplayWarningBeforeForcedLogoff and EnableServerInSingleUserMode

Reproduction steps

  1. Take Get-MapEntry from VMware.Hv.Helper
  2. Execute Set-HVGlobalGeneralSettings

    function Set-HVGlobalGeneralSettings {
    [CmdletBinding(
    SupportsShouldProcess = $false,
    ConfirmImpact = 'High'
    )]
    
    param(
    [Parameter(Mandatory = $false)]
    [boolean]
    $DisplayPreLoginMessage = $false
    )
    
    begin {
    $services = Get-ViewAPIService -hvServer $hvServer
    if ($null -eq $services) {
      Write-Error "Could not retrieve ViewApi services from connection object"
      break
    }
    }
    
    process {
    $updates = @()
    if ($DisplayPreLoginMessage) {
      $updates += Get-MapEntry -Key 'generalData.displayPreLoginMessage' -Value $DisplayPreLoginMessage
    }
    
    $services.GlobalSettings.GlobalSettings_Update($updates)
    }
    
    end {
    $services.GlobalSettings.GlobalSettings_Get().GeneralData
    }
    }

Expected behavior

DisplayPreLoginMessage updating without errors.

Additional context

Horizon Connection Server 8.8.0 build - 21073894 Powershell 5.1 PowerCLI 12.7

Mr-Kappelmann commented 4 months ago

I know about that module VMware.Hv.Helper has Set-HVGlobalSettings cmdlet, but some new properties from Horizon 2303 aren't in it. How to set new functions, that Set-HVGlobalSettings not provided? With -Key and -Value they are not working.

$hvServer = Connect-HVServer *hvServer*
$ViewAPI = $hvServer.ExtensionData
Set-HVGlobalSettings -Key 'GeneralData.EnableAutomaticStatusUpdates' -Value $true

same as

$update = New-Object VMware.Hv.MapEntry
$update.Key = "GeneralData.EnableAutomaticStatusUpdates"
$update.Value = $true
$ViewAPI.GlobalSettings.GlobalSettings_update($update)

same as

$service = New-Object VMware.Hv.GlobalSettingsService
$service.GlobalSettings_Update($ViewAPI, $update)

Error:
MethodInvocationException: Exception calling "GlobalSettings_Update" with "1" argument(s): "ExceptionType : VMware.Hv.InvalidArgument
ErrorMessage : Invalid member name.
ParameterName : GeneralData.EnableAutomaticStatusUpdates"

Request of value works:
(Get-HVGlobalSettings).GeneralData.EnableAutomaticStatusUpdates
False

$ViewAPI.GlobalSettings.GlobalSettings_Get().GeneralData.EnableAutomaticStatusUpdates
False

$service.GlobalSettings_Get($ViewAPI).GeneralData.EnableAutomaticStatusUpdates
False