Does anyone have any idea how to restart the management agents of a host using the PowerCLI for vsphere?
Not sure exactly which agent/service you're looking to restart but this works for restarting NTP
$vmhost = "your host"
Get-VmHostService -VMHost $vmhost | Where-Object {$_.key -eq "ntpd"} | Restart-VMHostService
Josh Atwell
In Restarting the Management agents on an ESX or ESXi Server it says that, on ESX, you have to restart mgmt-vmware and vmware-vpxa. The last one can be done with the Get-VMHostService cmdlet but the other one is not manageable from PowerCLI.
As a bypass, you can use the plink.exe command (from the PuTTY suite), provided you allow root SSH access.
In that case you could use a script like this
$User = "root" $Pswd = <root-password> $hostName = <ESX-hostname> $plink = "<PuTTY directory>\plink.exe" $plinkoptions = " -v -batch -pw $Pswd" $cmd1 = '/sbin/service mgmt-vmware restart' $remoteCommand = '"' + $cmd1 + '"' $command = $plink + " " + $plinkoptions + " " + $User + "@" + $hostName + " " + $remoteCommand Invoke-Expression -command $command $cmd2 = '/sbin/service vmware-vpxa restart' $remoteCommand = '"' + $cmd2 + '"' $command = $plink + " " + $plinkoptions + " " + $User + "@" + $hostName + " " + $remoteCommand Invoke-Expression -command $command
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference