Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This PowerCLI Script Uploads and Installs a ESXi Depot Package via ESXCLI -v2
[String]$ClusterName = "Compute01"
[String]$LocalPath = "D:\Image\"
[String]$DepotName = ""
[String]$TempDatastoreName = "LOCAL*"
$VMhosts = Get-Cluster -Name $ClusterName | Get-VMHost | Where-Object {$_.ConnectionState -eq "Maintenance"}
foreach ($VMhost in $VMhosts) {
#region: Upload Patch
$Datastore = $VMhost | Get-Datastore -Name $TempDatastoreName
$DatastoreDriveName = "HostStore_" + $VMhost.Name.Split(".")[0]
$Datastore | New-DatastoreDrive -Name $DatastoreDriveName | Out-Null
Copy-DatastoreItem -Item $LocalPath -Destination $($DatastoreDriveName + ":\") -Force:$true -Confirm:$false
Remove-PSDrive -Name $DatastoreDriveName
#region: Install Host Patch
$HostPath = $Datastore.ExtensionData.Info.Url.remove(0,5) + $DepotName
$esxcli2 = Get-ESXCLI -VMHost $VMhost -V2
$CreateArgs = $
$CreateArgs.depot = $HostPath
$InstallResponse = $$CreateArgs)
#region: Restart Host
if ($InstallResponse.RebootRequired -eq $true) {
Write-Host "Rebooting '$($VMHost.Name)'..."
Write-Host "VIBs Installed:"
$VMhost | Restart-VMHost -Confirm:$false | Out-Null
else {
Write-Host "No Reboot for '$($VMHost.Name)' required..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.