Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ESXi 仮想マシンのハードウェアバージョンのVUPをスケジュールする。
$vm_name = $args[0]
$target_vmx_version = $args[1]
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.ScheduledHardwareUpgradeInfo = New-Object VMware.Vim.ScheduledHardwareUpgradeInfo
$spec.ScheduledHardwareUpgradeInfo.UpgradePolicy = "always" # never or onSoftPowerOff or always
$spec.ScheduledHardwareUpgradeInfo.VersionKey = $target_vmx_version
$vms = Get-VM -Name $vm_name
$vms | ForEach-Object {
$vm = $_
$vm.ExtensionData.ReconfigVM($spec)
}
Get-VM -Name $vm_name | select `
Name,
Version,
@{N="Next_Version";E={$_.ExtensionData.Config.ScheduledHardwareUpgradeInfo.VersionKey}}
@gowatana

This comment has been minimized.

Copy link
Owner Author

@gowatana gowatana commented Nov 28, 2019

実行例。vm01,vm02をv9にバージョンアップ。
パワーオンされているVMにスクリプトを実行する。
VMを停止→起動するまで、バージョンはそのまま。

PowerCLI> .\vmx_schedule_vup.ps1 vm01,vm02 vmx-09

Name Version Next_Version
---- ------- ------------
vm02      v8 vmx-09
vm01      v8 vmx-09


PowerCLI> Get-VM vm01,vm02 | select Name,PowerState,Version

Name PowerState Version
---- ---------- -------
vm02  PoweredOn      v8
vm01  PoweredOn      v8

VM を 停止→起動

PowerCLI> Get-VM vm01,vm02 | Stop-VM -Confirm:$false

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
vm01                 PoweredOff 1        4.000
vm02                 PoweredOff 1        4.000


PowerCLI> Get-VM vm01,vm02 | Start-VM

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
vm02                 PoweredOn  1        4.000
vm01                 PoweredOn  1        4.000

バージョンがUPされる。

PowerCLI> Get-VM vm01,vm02 | select Name,PowerState,Version

Name PowerState Version
---- ---------- -------
vm02  PoweredOn      v9
vm01  PoweredOn      v9

以上

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.