Skip to content

Instantly share code, notes, and snippets.

@vMarkusK
Created February 22, 2018 08:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vMarkusK/e49a582c83c6a8fbfaea6c383cc71a99 to your computer and use it in GitHub Desktop.
Save vMarkusK/e49a582c83c6a8fbfaea6c383cc71a99 to your computer and use it in GitHub Desktop.
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