<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic VMware View API - Change recovery password in Horizon Desktops and Apps</title>
    <link>https://communities.vmware.com/t5/Horizon-Desktops-and-Apps/VMware-View-API-Change-recovery-password/m-p/2979455#M99726</link>
    <description>&lt;P&gt;Hello to everyone&lt;BR /&gt;&lt;SPAN&gt;I want to edit Recovery Password for my Horizon Connection Server. Below, you can see a couple of functions that should do this. But instead of a successful result, I see an error:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\Windows\system32&amp;gt; $Password = '12345678'
PS C:\Windows\system32&amp;gt; $Password = ConvertTo-SecureString -String $Password -AsPlainText -Force
PS C:\Windows\system32&amp;gt; Set-HvRecoveryPasswordExt -Password $Password
Exception calling "GlobalSettings_Update" with "1" argument(s): "ExceptionType : VMware.Hv.InvalidArgument
ErrorMessage : Invalid recovery password hash.
ParameterName : dataRecoveryPasswordData"
At C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper.Ext\VMware.Hv.Helper.Ext.psm1:1627 char:5
+     $services.GlobalSettings.GlobalSettings_Update($updates)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException


RecoveryPasswordSHA256 RecoveryPasswordHint
---------------------- --------------------
{123, 35, 45, 65...}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What's wrong with my approach? P.S: Documentation page&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developer.vmware.com/apis/1696/view" rel="nofollow noreferrer" target="_blank"&gt;https://developer.vmware.com/apis/1696/view&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function Set-HvRecoveryPasswordExt {
  param(
    [Parameter(Mandatory = $true)]
    [securestring]
    $Password,
    [Parameter(Mandatory = $false)]
    [string]
    $Hint
  )
  begin {
    $services = Get-ViewAPIService -hvServer $hvServer
    if ($null -eq $services) {
      Write-Error "Could not retrieve ViewApi services from connection object"
      break
    }
  }
  process {
    $tempPassword = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
    $plainePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($tempPassword)
    $Stream = [IO.MemoryStream]::new([byte[]][char[]]$plainePassword)
    $SHA256 = (Get-FileHash -InputStream $Stream -Algorithm SHA256).Hash
    $SHA256Bytes = [System.Text.Encoding]::UTF8.GetBytes($SHA256)
    $GlobalSettingsDataRecoveryPasswordData = New-Object VMware.Hv.GlobalSettingsDataRecoveryPasswordData -Property @{
      recoveryPasswordSHA256 = $SHA256Bytes
      recoveryPasswordHint = $Hint
    }
    $updates = Get-MapEntryExt -Key dataRecoveryPasswordData -Value $GlobalSettingsDataRecoveryPasswordData
    $services.GlobalSettings.GlobalSettings_Update($updates)
  }
  end {
    return $updates
    [System.gc]::collect()
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 09:15:25 GMT</pubDate>
    <dc:creator>po-temkin</dc:creator>
    <dc:date>2023-07-27T09:15:25Z</dc:date>
    <item>
      <title>VMware View API - Change recovery password</title>
      <link>https://communities.vmware.com/t5/Horizon-Desktops-and-Apps/VMware-View-API-Change-recovery-password/m-p/2979455#M99726</link>
      <description>&lt;P&gt;Hello to everyone&lt;BR /&gt;&lt;SPAN&gt;I want to edit Recovery Password for my Horizon Connection Server. Below, you can see a couple of functions that should do this. But instead of a successful result, I see an error:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\Windows\system32&amp;gt; $Password = '12345678'
PS C:\Windows\system32&amp;gt; $Password = ConvertTo-SecureString -String $Password -AsPlainText -Force
PS C:\Windows\system32&amp;gt; Set-HvRecoveryPasswordExt -Password $Password
Exception calling "GlobalSettings_Update" with "1" argument(s): "ExceptionType : VMware.Hv.InvalidArgument
ErrorMessage : Invalid recovery password hash.
ParameterName : dataRecoveryPasswordData"
At C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper.Ext\VMware.Hv.Helper.Ext.psm1:1627 char:5
+     $services.GlobalSettings.GlobalSettings_Update($updates)
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : VimException


RecoveryPasswordSHA256 RecoveryPasswordHint
---------------------- --------------------
{123, 35, 45, 65...}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What's wrong with my approach? P.S: Documentation page&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://developer.vmware.com/apis/1696/view" rel="nofollow noreferrer" target="_blank"&gt;https://developer.vmware.com/apis/1696/view&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function Set-HvRecoveryPasswordExt {
  param(
    [Parameter(Mandatory = $true)]
    [securestring]
    $Password,
    [Parameter(Mandatory = $false)]
    [string]
    $Hint
  )
  begin {
    $services = Get-ViewAPIService -hvServer $hvServer
    if ($null -eq $services) {
      Write-Error "Could not retrieve ViewApi services from connection object"
      break
    }
  }
  process {
    $tempPassword = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
    $plainePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($tempPassword)
    $Stream = [IO.MemoryStream]::new([byte[]][char[]]$plainePassword)
    $SHA256 = (Get-FileHash -InputStream $Stream -Algorithm SHA256).Hash
    $SHA256Bytes = [System.Text.Encoding]::UTF8.GetBytes($SHA256)
    $GlobalSettingsDataRecoveryPasswordData = New-Object VMware.Hv.GlobalSettingsDataRecoveryPasswordData -Property @{
      recoveryPasswordSHA256 = $SHA256Bytes
      recoveryPasswordHint = $Hint
    }
    $updates = Get-MapEntryExt -Key dataRecoveryPasswordData -Value $GlobalSettingsDataRecoveryPasswordData
    $services.GlobalSettings.GlobalSettings_Update($updates)
  }
  end {
    return $updates
    [System.gc]::collect()
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 09:15:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/Horizon-Desktops-and-Apps/VMware-View-API-Change-recovery-password/m-p/2979455#M99726</guid>
      <dc:creator>po-temkin</dc:creator>
      <dc:date>2023-07-27T09:15:25Z</dc:date>
    </item>
  </channel>
</rss>

