Is there a PowerCLI command to restart management agents on an ESXi 5.1 host?
The error is kind of unavoidable I'm afraid, you're cutting of the branch on which you are sitting :smileygrin:
But you can add the ErrorAction parameter, that way the error is still there, but you won't get flooded with error messages.
Get-VMHostService -VMHost MyEsx | where {$_.Key -eq "vpxa"} | Restart-VMHostService -Confirm:$false -ErrorAction SilentlyContinue
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-VMHostService -VMHost MyEsx |
where {$_.Key -eq "vpxa"} |
Restart-VMHostService -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK great - thanks. It seems to restart the agents, but it generates this error:
Restart-VMHostService : Restart-VMHostService An error occurred while communicating with
the remote host.
At line:1 char:106
+ get-vmhostservice -vmhost esx12.internal.com | where {$_.Key -eq "vpxa"} | Restart-VMHostService <<<< -conf
irm:$false
+ CategoryInfo : NotSpecified: (:) [Restart-VMHostService], HostCommunication
+ FullyQualifiedErrorId : Client20_SystemManagementServiceImpl_SetVMHostService_ViError,VMware.VimAutomation.ViCor
e.Cmdlets.Commands.RestartVMHostService
Can this error be avoided?
The error is kind of unavoidable I'm afraid, you're cutting of the branch on which you are sitting :smileygrin:
But you can add the ErrorAction parameter, that way the error is still there, but you won't get flooded with error messages.
Get-VMHostService -VMHost MyEsx | where {$_.Key -eq "vpxa"} | Restart-VMHostService -Confirm:$false -ErrorAction SilentlyContinue
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Great thanks again
Very useful script! Thanks LucD! I found I had to follow up with the following to get the host to reconnect to vCenter.
Start-Sleep 10
Set-VMHost -VMHost MyEsx -State "Connected"
This is great for the vpxa service but I can not seem to find a method to restart the hostd service via powershell.
Get-VMHostService -VMHost MyEsx <-- does not list the hostd service. Any ideas?
You are right, that service is not accessible through that cmdlet.
An alternative is to use the plink.exe command from the PuTTY Suite to set up a SSH connection to the ESXi server.
And then run your command inside the ESXi BusyBox.
There are multiple examples available on the usage of plink.exe in this community.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Lo use para ESX 6.5
Get-VMHost | foreach {Get-VMHostService -VMHost $_.name | where {$_.Key -eq "vpax"} | Restart-VMHostService }