vmware / PowerCLI-Example-Scripts

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

Desktop.Desktop_Update metod error #595

Closed Po-temkin closed 1 year ago

Po-temkin commented 1 year ago

Describe the bug

I tried to update Client Restrictions setting using Desktop_Update. What's wrong with my version?

Exception on call "Desktop_Update" with "2" arguments: "Failed to load type "VMware.Hv.String" from assembly "VMware.Hvi, Version=8.4.0.709, Culture=neutral, PublicKeyToken=null"."
string:1 symbol:2
+  $ViewAPI.Desktop.Desktop_Update($DesktopId,$MapEntryDesktopSettings)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : TypeLoadException

Reproduction steps

$DesktopEnabled = $true
$ConnectionServerRestrictions = @("Test1","Test2")
$ClientRestrictions = $true

$MapEntryDesktopSettings1 = New-Object VMware.Hv.MapEntry -Property @{Key='desktopSettings.enabled';Value=$DesktopEnabled}
$MapEntryDesktopSettings2 = New-Object VMware.Hv.MapEntry -Property @{Key='desktopSettings.connectionServerRestrictions';Value=$ConnectionServerRestrictions}
$MapEntryDesktopSettings3 = New-Object VMware.Hv.MapEntry -Property @{Key='desktopSettings.clientRestrictions';Value=$ClientRestrictions}

$MapEntryDesktopSettings  = @($MapEntryDesktopSettings1,$MapEntryDesktopSettings2,$MapEntryDesktopSettings3)

Expected behavior

Metod succesfully update Client Restrictions setting.

Additional context

Horizon Connection Server 8.6.0 build - 20099816 PowerCLI 12.7

Po-temkin commented 1 year ago

I resolved this problem. Desktop_Update metod required array of strings. Еherefore i needed to declare variable using [string[]] statement. Final code looks like this: [string[]] $ConnectionServerRestrictions = @('Test1','Test2')