Created
February 22, 2018 08:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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