I am fairly new to PowerShell and PowerCLI, so this may be a simple question, but I have searched around and cannot find a clear example that shows me what to do. I am running 5.0 GA ESXi, vCenter, and PowerCLI.
I want to install a network driver via Powercli in the same manner I would if I ssh directly to the host, i.e.
esxcli software vib install -v /vib_file_path/vib_file_name = what in Powercli?
I have created the object as outlined in the docs, and run down the tree using the Get-Member commandlet, so I know what I need is in
$esxcli.software.vib.install()
But I do not understand what options / invocation method is required to get the command to complete. When I run this with no options, i get the usage:
TypeNameOfValue : VMware.VimAutomation.ViCore.Util10Ps.EsxCliExtensionMethod
OverloadDefinitions : {vim.EsxCLI.software.vib.install.InstallationResult install(string[] depot, boolean dryrun, boolean force, boolean maintenancemode, boolean noliveinstall, boolean nosigcheck, string proxy, string[] vibname, string[] viburl)}
MemberType : CodeMethod
Value : vim.EsxCLI.software.vib.install.InstallationResult install(string[] depot, boolean dryrun, boolean force, boolean maintenancemode, boolean noliveinstall, boolean nosigcheck, string proxy, string[] vibname, string[] viburl)
Name : install
IsInstance : True
I am assuming that each of the pairs of brackets is a parameter, so I need give the command 3 options:
$esxcli.software.vib.install($1, $2, $3)
I have tried using a variation of these values, but the error I get is the same:
PowerCLI C:\> $test.software.vib.install($null, "net-ixgbe-3.4.23-1OEM.500.0.0.406165.x86_64.vib", "/store/")
The remote server returned an error: (500) Internal Server Error.
At line:1 char:27
+ $test.software.vib.install <<<< ($null, "net-ixgbe-3.4.23-1OEM.500.0.0.406165.x86_64.vib", "/store/")
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodInvocationException
Anybody see what i am doing wrong?
I'm afraid there are a few more parameters, like the message indicates
string[] depot
boolean dryrun
boolean force
boolean maintenancemode
boolean noliveinstall
boolean nosigcheck
string proxy
string[] vibname
string[] viburl
These correspond exactly with the parameters described in the ESXCLI command.
These are all positional parameters, so if there is a parameter you don't need, you still will have to pass something in that position.
$esxcli.software.vib.install($null,$true,$false,$true,$true,$false,$null,"net-ixgbe-3.4.23-1OEM.500.0.0.406165.x86_64.vib", "/store/")
This, or something similar, should do the trick.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I'm afraid there are a few more parameters, like the message indicates
string[] depot
boolean dryrun
boolean force
boolean maintenancemode
boolean noliveinstall
boolean nosigcheck
string proxy
string[] vibname
string[] viburl
These correspond exactly with the parameters described in the ESXCLI command.
These are all positional parameters, so if there is a parameter you don't need, you still will have to pass something in that position.
$esxcli.software.vib.install($null,$true,$false,$true,$true,$false,$null,"net-ixgbe-3.4.23-1OEM.500.0.0.406165.x86_64.vib", "/store/")
This, or something similar, should do the trick.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can someone confirm if this works ?
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.
Why don't you use the Install-VMHostPatch cmdlet to install the driver? This seems much easier to me.
I looked at using the Install-VMHostPatch cmdlet, but that requires the driver be built in patch form, i.e. the vib file with the metadata.zip. Often I only have access to the vib itself, so the esxcli software vib install command is my best option.
Thanks everyone for the suggestions. I have resorted to using Install-VMHostPatch for now. One limitation there is that there is no equivalent uinstall like a vib.remove .. So if I try the vib.remove I see the following error -- which leads me to believe that the powerCLI functionality has not been plumbed properly to the actual esxcli functionality ..
Looks like the vibname is not even getting passed to the invocation ..
There is indeed a problem in the Get-EsxCli when trying to use the 'remove' method.
But Alan shows the way around this in his Removing the vCD Agent from hosts post.
You have connect to the ESX(i) server instead of the vCenter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was able to use the method suggested by LucD. Since I was installing a Cisco vib for a nexus 1kv using a depot URL, my code looked like below:
$esxcli= Get-Esxcli -vmHost hostname.example.com
$ciscovibpath="/vmfs/volumes/datastore/Cisco_bootbank_cisco-vem-v152-esx_4.2.1.2.1.1a.0-3.0.1.vib"
$esxcli.software.vib.install($null,$null,$null,$null,$null,$null,$null,$null,$ciscovibpath)
Thanks for sharing that.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Using twoton's example of LucD's answer, I was able to modify my script and get my vibs to install without resorting to ssh. Thank you both.
Comparing the 2 methods, my ssh script seems to be faster, though that may be because I am getting more feedback messages.
Here is a simple script which can save a lot of time:
$hosts = Get-Cluster "Public Cluster" | Get-VMHost
foreach($vihost in $hosts){
$esxcli = get-vmhost $vihost | Get-EsxCli
$esxcli.software.vib.update($null,$false,$false,$false,$false,$true,$null,$null,"/vmfs/volumes/DATASTORE/VMware_locker_tools-light_5.1.0-2.44.2191751.vib")
}
P.S. Please, have in mind that when you have a vib file you have to specify "string[] viburl" and leave "string[] vibname" empty (the example provided by LucD is not entirely correct).
I stand corrected, I didn't know that
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Neither do I.
I spent several minutes to figured out that and I thought it would be a good idea if I share this here.
I don't know if this is the right place but: also there is another interesting fact: "boolean maintenancemode" doesn't work (I set it to $true). I put two hosts in maintenance mode but the script above patched all hosts in the cluster without skipping the hosts which are not in maintenance mode. The version of the vCenter Server is "vCenter Server 5.1 Update 2a", ESXi "ESXi 5.1 Patch 5" (all hosts), PowerCLI 5.8 Release 1 (I also tried with PowerCLI 5.1 Release 1).
I would like to express my gratitude here for the information you have shared.
This information saved me a couple of hours.