Horizon 8 (non REST) Script for scheduled refresh doesn't work
Hi,
We've recently upgraded to VMware Horizon 8 and we want to have a nightly refresh for all our VDI VMs. After searching online, I've created the following script.
However, when I run the script, there's nothing happening within vCenter or View admin dasboard with the VMs I like to refresh.
I'm using the following script:
$KeyFilePath = 'C:\Scripts\VDIscript\key_.key'
$CredPath = 'C:\Scripts\VDIscript\Cred.xml'
$ErrorActionPreference = 'SilentlyContinue'
Start-Transcript -Path 'C:\Scripts\VDIscript\Refresh-DesktopsByAPI.log' -Force
#decrypt credentials
$Key = Get-Content $KeyFilePath
$credXML = Import-Clixml $CredPath # Import encrypted credential file into XML format
$secureStringPWD = ConvertTo-SecureString -String $credXML.Password -Key $key
$Credential = New-Object System.Management.Automation.PsCredential($credXML.UserName, $secureStringPWD) # Create PScredential Object
Write-Host "Loading VMware modules" -ForegroundColor Green
Import-Module -Name VMware.VimAutomation.HorizonView
#Connect to the Horizon View connection server
$hvServer = Connect-HVServer -Server 'FQDN servername' -User saView8scheduledtask -Password 'INSERTPASSWORD' -Domain DOMAIN.local
$services = $hvServer.ExtensionData
$spechelper=New-Object VMware.Hv.DesktopService+DesktopRefreshSpecHelper
$specbase=New-Object VMware.Hv.DesktopRefreshSpec
$Machines = (get-hvmachine | where { $_.base.DesktopName -eq "FL-W10-Basic-POC" })
#[Vmware.Hv.machineid]$machineIDs=(Get-HVMachine -PoolName "FL-W10-Basic-POC").id
$machineIDs=(Get-HVMachine -PoolName "FL-W10-Basic-POC").id
# DesktopID is PoolID
$PoolID = (Get-HVPool -PoolName "FL-W10-Basic-POC").id
$Machines.base.desktop | foreach {
$desktoprefreshSpec.StartTime = $null
[Vmware.Hv.DesktopID]$deskid=$PoolID
$spec=$specbase
$spec.logoffsetting=$spechelper.LOGOFF_SETTING_FORCE_LOGOFF
$spec.machines=$machineIDs
$services.desktop.desktop_refresh($deskid, $spec)
}
disconnect-HVServer -Server $hvServices -Confirm:$false
Stop-Transcript
When I put a breakpoint in the script and halt it before running the line:
$services.desktop.desktop_refresh($deskid, $spec)
I see the following data within the key variables: (see attached screenshot)

Could somebody tell me what I'm missing here?