“My problem”

A lot of my customers running VMware Horizon have been using NVIDIA GPU’s in their ESXi hosts leveraging vGPU to accelerate their virtual desktops, especially since they made the move to Windows 10. When using vGPU one of the requirements is the installation of a driver on the ESXi host(s) which has the NVIDIA card installed.

But when you add a component this also means you’ll have to maintain it, meaning from time to time it will require updating. Especially since NVIDIA introduced two separate release branches:

  • Long-Term support branch – which has support for three years after the initial release
  • New-Feature branch –  which has support for one year after the initial release

Seeing as both VMware and Microsoft frequently release new versions of their products it’s import to keep the entire chain in a supported state, which can be a puzzle sometimes.
Luckily VMware has a KB article which describes the process of updating the driver. In short it comes down to:

  • Make sure there are no VM’s running on the host using the graphics card
  • Place the host in maintenance mode
  • Uninstall the VIB
  • Install the new VIB

Especially the part where you uninstall and install the VIB can be time consuming job, as you normally do this through a command prompt on the ESXi host. So when you have to do this on several ESXi hosts you can image the amount of time and effort it takes to complete this task.

“My solution”

To make it less of a hassle I’ve written a PowerCLI script which removes a specified VIB of all ESXi hosts which are in maintenance mode.

In short the script saves all ESXi hosts in maintenance mode in a variable, and loops the removal of the specified VIB (in this case the NVIDIA one). Expect an updated version soon, as I’m working on a version which includes automatically rebooting the ESXi hosts (when required) and installing the new VIB afterwards.

You can download or copy the code in it’s current state below.

 <#
.SYNOPSIS
    Uninstall_VIB_from_multiple_hosts.ps1 - PowerShell Script to remove VIBs from one or more ESXi hosts.
.DESCRIPTION
    This script is used to delete a VIB from one or more ESXi hosts (depending on how you change line 15).
    By default the script will run against all ESXi hosts which are placed in maintenance mode.
    At this moment rebooting a host is a manual action, the requirement of a reboot will be printed to the console
.OUTPUTS
    Results are printed to the console.
.NOTES
    Author        Jesper Alberts, Twitter: @jesperalberts, Blog: www.vjal.nl

    Change Log    V1.00, 22/07/2019 - Initial version
#>

$vCenterServer = Read-Host "Enter the vCenter Server hostname"
$AdminUsername = Read-Host ("Enter the username for the administrative account")
$AdminPassword = Read-Host ("Password for " + $AdminUsername) -AsSecureString:$true
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $AdminUsername, $AdminPassword

Connect-VIServer -Server $vCenterServer -Credential $Credentials

$ESXiHosts = Get-VMHost | Where { $_.ConnectionState -eq "Maintenance" }
$VIBs = @("NVIDIA-VMware_ESXi_6.7_Host_Driver")

Foreach ($ESXiHost in $ESXiHosts) {
    Write-host "Working on $ESXiHost."
    $ESXCLI = get-esxcli -vmhost $ESXiHost
    foreach ($VIB in ($VIBs)) {
        write-host "Searching for VIB $VIB." -ForegroundColor Cyan
        if ($ESXCLI.software.vib.get.invoke() | where { $_.name -eq "$VIB" } -erroraction silentlycontinue ) {
            write-host "Found vib $VIB on $ESXiHost, deleting." -ForegroundColor Green
            $ESXCLI.software.vib.remove.invoke($null, $true, $false, $true, "$VIB")
        }
        else {
            write-host "VIB $VIB not found on $ESXiHost." -ForegroundColor Yellow
        }
    }
}
Please follow and like us:
2 thoughts on “Uninstalling a VIB leveraging PowerCLI”
  1. This is the same as all of the other scripts that I have found. What I REALLY need is a script that will invoke the remove command, and then move on to the next host, without waiting for the VIB to be removed first. I have over 800 hosts that I need to remove 2 VIBs from, and if I have to wait for each of the two VIBs to be removed from each of the hosts before the script can continue to the next VIB/host, it’s going to take 3 days for this script to complete. Is there no way to kick off the VIB removal process, and then move on to the next host immediately? I know I can’t remove more than 1 VIB from a host at a time, so I would still need to run the script twice… Once for the first VIB, and a second time for the second VIB, but if it could just kick the removal command off, and then move on, it would only take me about an hour to remove these VIBs, rather than a few days.

    1. You’re absolutely right that this will take a long time. Back when I wrote this script the Parallel feature wasn’t available yet and unfortunately you cannot use -RunAsync.

      I’ll try and see if I can create a new version of the script during the next couple of days using ForEach -parallel, and compare it to the current version.

Leave a Reply

Your email address will not be published. Required fields are marked *