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

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

Open Po-temkin opened this issue 2 years ago • 1 comments

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
    [System.gc]::collect()
  }
}

Expected behavior

DisplayPreLoginMessage updating without errors.

Additional context

Horizon Connection Server 8.8.0 build - 21073894 Powershell 5.1 PowerCLI 12.7

Po-temkin avatar Mar 20 '23 15:03 Po-temkin

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

Mr-Kappelmann avatar Feb 06 '24 06:02 Mr-Kappelmann