srlawton
Contributor
Contributor

I tried following the advice above, but still could not get my hosts to respond correctly. I finally dropped trying to run get-esxcli, and just used plink in my powershell script to ssh into the host, and run the esxcli install command in the busybox shell. Here is my script.

# Script to call plink and run a command via ssh directly on a host
# Requires that the Putty install directory be listed in the path statement
# Requires that PowerCLI be connected to each host individually.
# Assumes the driver.vib file has been uploaded to the local data store of the host.
# Assumes that the local datastore containing the vib driver file has "local" somewhere in the name.

#ESX Host login information
$user="root"
$pswd="password"

$ESXHost = Get-VMHost | Sort Name | ForEach {
      #Find the local datastore via name
      $DataStore = $_ | Get-Datastore | where{$_.Name -match "local"}
      #Build host DataStore path
      $DSPath = "/vmfs/volumes/$Datastore"
      #Get the hostname for plink to use
      $ID = % {$_.Name}
      #Use the PowerCLI drive provider to find the latest driver vib uploaded to the host
      $VIB = ls vmstores:\$ID@443\ha-datacenter\$DataStore\*.vib | sort LastWriteTime | select -last 1 | % {$_.Name}
      #Output what we found to make sure it is correct
      write-host $ID
      write-host $VIB
      #Build the ESX shell command we need to run to install the drivers
      $remoteCommand = "esxcli software vib install -v " + $DSPath + "/" + $VIB
      #Output what we built to make sure it is correct
      write-host $remoteCommand

      #Place host into Maintenance Mode
      If ($_.ConnectionState -notmatch "Maintenance"){$_ | Set-VMHost -State Maintenance}

      #Run the plink command
      $msg = plink -v -batch -pw $pswd $user@$ID $remoteCommand
      #output the plink results
      write-host $msg

      #Restart Host   
      $_ | Restart-VMHost -Confirm:$false
}

There are several short cuts I am taking because I have a very focused group of hosts with a strict host config that I control when I bring up a new server.

You may not have ssh enabled, for instance, or the same username and password on each of your hosts.

Reply
0 Kudos