You would probably want to write that more along the lines of the below:
$user = "root"
$password = "Password"
$vmhosts = Get-VMHost | Select Name
Foreach ($vmhost in $vmhosts){
Write-Host "Processing "$vmhost.Name
Connect-VIServer $vmhost.Name -User $user -Password $password | Out-Null
$HealthSystem = (Get-View (Get-VMHost | Get-View).ConfigManager.HealthStatusSystem)
$HealthSystem.ResetSystemHealthInfo()
$HealthSystem.UpdateViewData()
$HealthSystem.RefreshHealthStatusSystem()
Disconnect-VIServer -Confirm:$false
Write-Host "Starting Next Host"
}
If you run that as script while connected to your vCenter it will pull all of your hosts and connect directly to them to refresh them.