*Updated the script slightly.* https://get-cj.com/2018/04/02/how-to-refresh-vmware-horizon-desktops-using-powershell-powercli/ I was inspired by pegduffy after you posted that snippet of c...
See more...
*Updated the script slightly.* https://get-cj.com/2018/04/02/how-to-refresh-vmware-horizon-desktops-using-powershell-powercli/ I was inspired by pegduffy after you posted that snippet of code. I wrote a new function that refreshes a desktop or a list of desktops. Much of the reference for this comes from the various VMWare sites and Horizon API reference pages. Please post your solution as well when you find it. If you want It's good to see the way others do it. Good learning experience. Example: $machines = ('machinename1', 'machinename2') refresh-ViewDesktop -machines $machines -viewserver 'Horizon_Connection_Server' function refresh-ViewDesktop { [CmdletBinding()] [OutputType([PSCustomObject])] param( [string[]]$machines, [string]$viewserver ) $cred = Get-Credential $hvServer = Connect-HVServer -server $viewserver -Credential $cred $hvServices = $hvServer.ExtensionData $queryService = New-Object VMware.Hv.QueryServiceService $query = New-Object VMware.Hv.QueryDefinition $query.queryEntityType = 'MachineNamesView' [VMware.Hv.QueryFilter []] $filters = @() foreach ($machine in $machines){ $filters += new-object VMware.Hv.QueryFilterEquals -property @{'memberName' = 'base.name'; 'value' = $machine} } $orFilter = new-object VMware.Hv.QueryFilterOr -property @{'filters' = $filters} $query.Filter = $orFilter $queryResults = $queryService.QueryService_Create($hvServices,$query) $finalmachine = @() foreach ($result in $queryResults.Results){ [VMware.Hv.MachineNamesView]$machineNamesView = $result $properties = @{ machineid = $machineNamesView.id names = $machineNamesView.base.name desktopId = $machineNamesView.base.Desktop } $finalmachine += New-Object -TypeName pscustomobject -Property $properties } $desktopService = New-Object VMware.Hv.DesktopService $machineService = New-Object VMware.Hv.MachineService foreach($object in $finalmachine){ $desktoprefreshSpec = New-Object VMware.Hv.DesktopRefreshSpec $desktoprefresheSpecHelper = New-Object VMware.Hv.DesktopService+DesktopRefreshSpecHelper $desktoprefreshSpec.Machines = $object.machineid $desktoprefreshSpec.LogoffSetting = $desktoprefresheSpecHelper.LOGOFF_SETTING_FORCE_LOGOFF $desktoprefreshSpec.StartTime = $null $desktopService.Desktop_Refresh($hvServices, $machineNamesView.base.Desktop,$desktoprefreshSpec) Write-Output "" Write-Output "Refreshing Machines" $($object.names) } } Disclaimer: ~I'm just an IT enthusiast with no certs, no degrees, no training, in any of this crap, but I know my way around google so that's all that matters. -Jose Rodriguez~