Automation

 View Only
  • 1.  Restart Management Agents with vSphere PowerCLI

    Posted Oct 13, 2009 02:51 PM

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



  • 2.  RE: Restart Management Agents with vSphere PowerCLI

    Posted Oct 13, 2009 08:29 PM

    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



  • 3.  RE: Restart Management Agents with vSphere PowerCLI

    Posted Oct 14, 2009 06:41 AM

    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