Skip to content

Instantly share code, notes, and snippets.

Embed
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\HPE-20180220.zip"
[String]$DepotName = "HPE-20180220.zip"
[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
#endregion
#region: Install Host Patch
$HostPath = $Datastore.ExtensionData.Info.Url.remove(0,5) + $DepotName
$esxcli2 = Get-ESXCLI -VMHost $VMhost -V2
$CreateArgs = $esxcli2.software.vib.install.CreateArgs()
$CreateArgs.depot = $HostPath
$InstallResponse = $esxcli2.software.vib.install.Invoke($CreateArgs)
#endregion
#region: Restart Host
if ($InstallResponse.RebootRequired -eq $true) {
Write-Host "Rebooting '$($VMHost.Name)'..."
Write-Host "VIBs Installed:"
$InstallResponse.VIBsInstalled
$VMhost | Restart-VMHost -Confirm:$false | Out-Null
}
else {
Write-Host "No Reboot for '$($VMHost.Name)' required..."
}
#endregion
}
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.