VMware Cloud Community
thmadd
Contributor
Contributor

Restart Management Agents with vSphere PowerCLI

Does anyone have any idea how to restart the management agents of a host using the PowerCLI for vsphere?

2 Replies
aerodevil
Hot Shot
Hot Shot

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

Josh Atwell @Josh_Atwell http://www.vtesseract.com http://github.com/joshatwell/
Reply
0 Kudos
LucD
Leadership
Leadership

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