Windows10のHyper-V仮想マシンを素早く起動する方法

Windows10のHyper-Vで稼働する仮想マシンを操作する場合、管理ツールである「Hyper-Vマネージャー」を使用するのが一般的ですが、Windows PowerShellコマンドレットを利用して操作することもできます。

そこで、ここでは仮想マシンの操作で最も頻繁に行う「仮想マシンの起動」をコマンドから実行することで、仮想マシンの起動を効率化する方法を紹介します。

動作環境

この記事は、以下の環境で実行した結果を基にしています。他のエディションやバージョンでは、動作結果が異なる場合があることをご了承ください。

ソフトウェア バージョン
Windows10 Pro 64bit 1903

スクリプトファイルの作成

仮想マシンを起動するスクリプトファイルの作成方法は、次のとおりです。

メモ帳などのテキストエディターで下記の内容を入力し、デスクトップなどの任意の場所にバッチファイル(拡張子bat)として保存します。

なお、変数「VMNAME」の値(ここでは「win10」と入力しています)は、起動させたい仮想マシン名に置き換えてください。

@echo off
set VMNAME="win10"

powershell.exe -ExecutionPolicy Bypass -Command "Start-VM %VMNAME%"
vmconnect.exe 127.0.0.1 %VMNAME%

なお、作成したバッチファイルを実行する際は、バッチファイルを右クリックして「管理者権限で実行」を選択して実行します。

バッチファイルを実行すると、仮想マシンが起動するとともに、仮想マシンのウィンドウが開くはずです。

Hyper-V用のPowerShellコマンドレット

ちなみに、Hyper-Vの操作や設定に関するPowerShellコマンドレットは200個以上あります。ここで紹介した起動以外でも活用できそうです。

> Get-Command -Module Hyper-V

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Add-VMAssignableDevice                             2.0.0.0    Hyper-V
Cmdlet          Add-VMDvdDrive                                     2.0.0.0    Hyper-V
Cmdlet          Add-VMFibreChannelHba                              2.0.0.0    Hyper-V
Cmdlet          Add-VMGpuPartitionAdapter                          2.0.0.0    Hyper-V
Cmdlet          Add-VMGroupMember                                  2.0.0.0    Hyper-V
Cmdlet          Add-VMHardDiskDrive                                2.0.0.0    Hyper-V
Cmdlet          Add-VMHostAssignableDevice                         2.0.0.0    Hyper-V
Cmdlet          Add-VMKeyStorageDrive                              2.0.0.0    Hyper-V
Cmdlet          Add-VMMigrationNetwork                             2.0.0.0    Hyper-V
Cmdlet          Add-VMNetworkAdapter                               2.0.0.0    Hyper-V
Cmdlet          Add-VMNetworkAdapterAcl                            2.0.0.0    Hyper-V
Cmdlet          Add-VMNetworkAdapterExtendedAcl                    2.0.0.0    Hyper-V
Cmdlet          Add-VMNetworkAdapterRoutingDomainMapping           2.0.0.0    Hyper-V
Cmdlet          Add-VMPmemController                               2.0.0.0    Hyper-V
Cmdlet          Add-VMRemoteFx3dVideoAdapter                       2.0.0.0    Hyper-V
Cmdlet          Add-VMScsiController                               2.0.0.0    Hyper-V
Cmdlet          Add-VMStoragePath                                  2.0.0.0    Hyper-V
Cmdlet          Add-VMSwitch                                       2.0.0.0    Hyper-V
Cmdlet          Add-VMSwitchExtensionPortFeature                   2.0.0.0    Hyper-V
Cmdlet          Add-VMSwitchExtensionSwitchFeature                 2.0.0.0    Hyper-V
Cmdlet          Add-VMSwitchTeamMember                             2.0.0.0    Hyper-V
Cmdlet          Checkpoint-VM                                      2.0.0.0    Hyper-V
Cmdlet          Compare-VM                                         2.0.0.0    Hyper-V
Cmdlet          Complete-VMFailover                                2.0.0.0    Hyper-V
Cmdlet          Connect-VMNetworkAdapter                           2.0.0.0    Hyper-V
Cmdlet          Connect-VMSan                                      2.0.0.0    Hyper-V
Cmdlet          Convert-VHD                                        2.0.0.0    Hyper-V
Cmdlet          Copy-VMFile                                        2.0.0.0    Hyper-V
Cmdlet          Debug-VM                                           2.0.0.0    Hyper-V
Cmdlet          Disable-VMConsoleSupport                           2.0.0.0    Hyper-V
Cmdlet          Disable-VMEventing                                 2.0.0.0    Hyper-V
Cmdlet          Disable-VMIntegrationService                       2.0.0.0    Hyper-V
Cmdlet          Disable-VMMigration                                2.0.0.0    Hyper-V
Cmdlet          Disable-VMRemoteFXPhysicalVideoAdapter             2.0.0.0    Hyper-V
Cmdlet          Disable-VMResourceMetering                         2.0.0.0    Hyper-V
Cmdlet          Disable-VMSwitchExtension                          2.0.0.0    Hyper-V
Cmdlet          Disable-VMTPM                                      2.0.0.0    Hyper-V
Cmdlet          Disconnect-VMNetworkAdapter                        2.0.0.0    Hyper-V
Cmdlet          Disconnect-VMSan                                   2.0.0.0    Hyper-V
Cmdlet          Dismount-VHD                                       2.0.0.0    Hyper-V
Cmdlet          Dismount-VMHostAssignableDevice                    2.0.0.0    Hyper-V
Cmdlet          Enable-VMConsoleSupport                            2.0.0.0    Hyper-V
Cmdlet          Enable-VMEventing                                  2.0.0.0    Hyper-V
Cmdlet          Enable-VMIntegrationService                        2.0.0.0    Hyper-V
Cmdlet          Enable-VMMigration                                 2.0.0.0    Hyper-V
Cmdlet          Enable-VMRemoteFXPhysicalVideoAdapter              2.0.0.0    Hyper-V
Cmdlet          Enable-VMReplication                               2.0.0.0    Hyper-V
Cmdlet          Enable-VMResourceMetering                          2.0.0.0    Hyper-V
Cmdlet          Enable-VMSwitchExtension                           2.0.0.0    Hyper-V
Cmdlet          Enable-VMTPM                                       2.0.0.0    Hyper-V
Cmdlet          Export-VM                                          2.0.0.0    Hyper-V
Cmdlet          Export-VMSnapshot                                  2.0.0.0    Hyper-V
Cmdlet          Get-VHD                                            2.0.0.0    Hyper-V
Cmdlet          Get-VHDSet                                         2.0.0.0    Hyper-V
Cmdlet          Get-VHDSnapshot                                    2.0.0.0    Hyper-V
Cmdlet          Get-VM                                             2.0.0.0    Hyper-V
Cmdlet          Get-VMAssignableDevice                             2.0.0.0    Hyper-V
Cmdlet          Get-VMBios                                         2.0.0.0    Hyper-V
Cmdlet          Get-VMComPort                                      2.0.0.0    Hyper-V
Cmdlet          Get-VMConnectAccess                                2.0.0.0    Hyper-V
Cmdlet          Get-VMDvdDrive                                     2.0.0.0    Hyper-V
Cmdlet          Get-VMFibreChannelHba                              2.0.0.0    Hyper-V
Cmdlet          Get-VMFirmware                                     2.0.0.0    Hyper-V
Cmdlet          Get-VMFloppyDiskDrive                              2.0.0.0    Hyper-V
Cmdlet          Get-VMGpuPartitionAdapter                          2.0.0.0    Hyper-V
Cmdlet          Get-VMGroup                                        2.0.0.0    Hyper-V
Cmdlet          Get-VMHardDiskDrive                                2.0.0.0    Hyper-V
Cmdlet          Get-VMHost                                         2.0.0.0    Hyper-V
Cmdlet          Get-VMHostAssignableDevice                         2.0.0.0    Hyper-V
Cmdlet          Get-VMHostCluster                                  2.0.0.0    Hyper-V
Cmdlet          Get-VMHostNumaNode                                 2.0.0.0    Hyper-V
Cmdlet          Get-VMHostNumaNodeStatus                           2.0.0.0    Hyper-V
Cmdlet          Get-VMHostSupportedVersion                         2.0.0.0    Hyper-V
Cmdlet          Get-VMIdeController                                2.0.0.0    Hyper-V
Cmdlet          Get-VMIntegrationService                           2.0.0.0    Hyper-V
Cmdlet          Get-VMKeyProtector                                 2.0.0.0    Hyper-V
Cmdlet          Get-VMKeyStorageDrive                              2.0.0.0    Hyper-V
Cmdlet          Get-VMMemory                                       2.0.0.0    Hyper-V
Cmdlet          Get-VMMigrationNetwork                             2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapter                               2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterAcl                            2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterExtendedAcl                    2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterFailoverConfiguration          2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterIsolation                      2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterRdma                           2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterRoutingDomainMapping           2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterTeamMapping                    2.0.0.0    Hyper-V
Cmdlet          Get-VMNetworkAdapterVlan                           2.0.0.0    Hyper-V
Cmdlet          Get-VMPartitionableGpu                             2.0.0.0    Hyper-V
Cmdlet          Get-VMPmemController                               2.0.0.0    Hyper-V
Cmdlet          Get-VMProcessor                                    2.0.0.0    Hyper-V
Cmdlet          Get-VMRemoteFx3dVideoAdapter                       2.0.0.0    Hyper-V
Cmdlet          Get-VMRemoteFXPhysicalVideoAdapter                 2.0.0.0    Hyper-V
Cmdlet          Get-VMReplication                                  2.0.0.0    Hyper-V
Cmdlet          Get-VMReplicationAuthorizationEntry                2.0.0.0    Hyper-V
Cmdlet          Get-VMReplicationServer                            2.0.0.0    Hyper-V
Cmdlet          Get-VMResourcePool                                 2.0.0.0    Hyper-V
Cmdlet          Get-VMSan                                          2.0.0.0    Hyper-V
Cmdlet          Get-VMScsiController                               2.0.0.0    Hyper-V
Cmdlet          Get-VMSecurity                                     2.0.0.0    Hyper-V
Cmdlet          Get-VMSnapshot                                     2.0.0.0    Hyper-V
Cmdlet          Get-VMStoragePath                                  2.0.0.0    Hyper-V
Cmdlet          Get-VMStorageSettings                              2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitch                                       2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitchExtension                              2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitchExtensionPortData                      2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitchExtensionPortFeature                   2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitchExtensionSwitchData                    2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitchExtensionSwitchFeature                 2.0.0.0    Hyper-V
Cmdlet          Get-VMSwitchTeam                                   2.0.0.0    Hyper-V
Cmdlet          Get-VMSystemSwitchExtension                        2.0.0.0    Hyper-V
Cmdlet          Get-VMSystemSwitchExtensionPortFeature             2.0.0.0    Hyper-V
Cmdlet          Get-VMSystemSwitchExtensionSwitchFeature           2.0.0.0    Hyper-V
Cmdlet          Get-VMVideo                                        2.0.0.0    Hyper-V
Cmdlet          Grant-VMConnectAccess                              2.0.0.0    Hyper-V
Cmdlet          Import-VM                                          2.0.0.0    Hyper-V
Cmdlet          Import-VMInitialReplication                        2.0.0.0    Hyper-V
Cmdlet          Measure-VM                                         2.0.0.0    Hyper-V
Cmdlet          Measure-VMReplication                              2.0.0.0    Hyper-V
Cmdlet          Measure-VMResourcePool                             2.0.0.0    Hyper-V
Cmdlet          Merge-VHD                                          2.0.0.0    Hyper-V
Cmdlet          Mount-VHD                                          2.0.0.0    Hyper-V
Cmdlet          Mount-VMHostAssignableDevice                       2.0.0.0    Hyper-V
Cmdlet          Move-VM                                            2.0.0.0    Hyper-V
Cmdlet          Move-VMStorage                                     2.0.0.0    Hyper-V
Cmdlet          New-VFD                                            2.0.0.0    Hyper-V
Cmdlet          New-VHD                                            2.0.0.0    Hyper-V
Cmdlet          New-VM                                             2.0.0.0    Hyper-V
Cmdlet          New-VMGroup                                        2.0.0.0    Hyper-V
Cmdlet          New-VMReplicationAuthorizationEntry                2.0.0.0    Hyper-V
Cmdlet          New-VMResourcePool                                 2.0.0.0    Hyper-V
Cmdlet          New-VMSan                                          2.0.0.0    Hyper-V
Cmdlet          New-VMSwitch                                       2.0.0.0    Hyper-V
Cmdlet          Optimize-VHD                                       2.0.0.0    Hyper-V
Cmdlet          Optimize-VHDSet                                    2.0.0.0    Hyper-V
Cmdlet          Remove-VHDSnapshot                                 2.0.0.0    Hyper-V
Cmdlet          Remove-VM                                          2.0.0.0    Hyper-V
Cmdlet          Remove-VMAssignableDevice                          2.0.0.0    Hyper-V
Cmdlet          Remove-VMDvdDrive                                  2.0.0.0    Hyper-V
Cmdlet          Remove-VMFibreChannelHba                           2.0.0.0    Hyper-V
Cmdlet          Remove-VMGpuPartitionAdapter                       2.0.0.0    Hyper-V
Cmdlet          Remove-VMGroup                                     2.0.0.0    Hyper-V
Cmdlet          Remove-VMGroupMember                               2.0.0.0    Hyper-V
Cmdlet          Remove-VMHardDiskDrive                             2.0.0.0    Hyper-V
Cmdlet          Remove-VMHostAssignableDevice                      2.0.0.0    Hyper-V
Cmdlet          Remove-VMKeyStorageDrive                           2.0.0.0    Hyper-V
Cmdlet          Remove-VMMigrationNetwork                          2.0.0.0    Hyper-V
Cmdlet          Remove-VMNetworkAdapter                            2.0.0.0    Hyper-V
Cmdlet          Remove-VMNetworkAdapterAcl                         2.0.0.0    Hyper-V
Cmdlet          Remove-VMNetworkAdapterExtendedAcl                 2.0.0.0    Hyper-V
Cmdlet          Remove-VMNetworkAdapterRoutingDomainMapping        2.0.0.0    Hyper-V
Cmdlet          Remove-VMNetworkAdapterTeamMapping                 2.0.0.0    Hyper-V
Cmdlet          Remove-VMPmemController                            2.0.0.0    Hyper-V
Cmdlet          Remove-VMRemoteFx3dVideoAdapter                    2.0.0.0    Hyper-V
Cmdlet          Remove-VMReplication                               2.0.0.0    Hyper-V
Cmdlet          Remove-VMReplicationAuthorizationEntry             2.0.0.0    Hyper-V
Cmdlet          Remove-VMResourcePool                              2.0.0.0    Hyper-V
Cmdlet          Remove-VMSan                                       2.0.0.0    Hyper-V
Cmdlet          Remove-VMSavedState                                2.0.0.0    Hyper-V
Cmdlet          Remove-VMScsiController                            2.0.0.0    Hyper-V
Cmdlet          Remove-VMSnapshot                                  2.0.0.0    Hyper-V
Cmdlet          Remove-VMStoragePath                               2.0.0.0    Hyper-V
Cmdlet          Remove-VMSwitch                                    2.0.0.0    Hyper-V
Cmdlet          Remove-VMSwitchExtensionPortFeature                2.0.0.0    Hyper-V
Cmdlet          Remove-VMSwitchExtensionSwitchFeature              2.0.0.0    Hyper-V
Cmdlet          Remove-VMSwitchTeamMember                          2.0.0.0    Hyper-V
Cmdlet          Rename-VM                                          2.0.0.0    Hyper-V
Cmdlet          Rename-VMGroup                                     2.0.0.0    Hyper-V
Cmdlet          Rename-VMNetworkAdapter                            2.0.0.0    Hyper-V
Cmdlet          Rename-VMResourcePool                              2.0.0.0    Hyper-V
Cmdlet          Rename-VMSan                                       2.0.0.0    Hyper-V
Cmdlet          Rename-VMSnapshot                                  2.0.0.0    Hyper-V
Cmdlet          Rename-VMSwitch                                    2.0.0.0    Hyper-V
Cmdlet          Repair-VM                                          2.0.0.0    Hyper-V
Cmdlet          Reset-VMReplicationStatistics                      2.0.0.0    Hyper-V
Cmdlet          Reset-VMResourceMetering                           2.0.0.0    Hyper-V
Cmdlet          Resize-VHD                                         2.0.0.0    Hyper-V
Cmdlet          Restart-VM                                         2.0.0.0    Hyper-V
Cmdlet          Restore-VMSnapshot                                 2.0.0.0    Hyper-V
Cmdlet          Resume-VM                                          2.0.0.0    Hyper-V
Cmdlet          Resume-VMReplication                               2.0.0.0    Hyper-V
Cmdlet          Revoke-VMConnectAccess                             2.0.0.0    Hyper-V
Cmdlet          Save-VM                                            2.0.0.0    Hyper-V
Cmdlet          Set-VHD                                            2.0.0.0    Hyper-V
Cmdlet          Set-VM                                             2.0.0.0    Hyper-V
Cmdlet          Set-VMBios                                         2.0.0.0    Hyper-V
Cmdlet          Set-VMComPort                                      2.0.0.0    Hyper-V
Cmdlet          Set-VMDvdDrive                                     2.0.0.0    Hyper-V
Cmdlet          Set-VMFibreChannelHba                              2.0.0.0    Hyper-V
Cmdlet          Set-VMFirmware                                     2.0.0.0    Hyper-V
Cmdlet          Set-VMFloppyDiskDrive                              2.0.0.0    Hyper-V
Cmdlet          Set-VMGpuPartitionAdapter                          2.0.0.0    Hyper-V
Cmdlet          Set-VMHardDiskDrive                                2.0.0.0    Hyper-V
Cmdlet          Set-VMHost                                         2.0.0.0    Hyper-V
Cmdlet          Set-VMHostCluster                                  2.0.0.0    Hyper-V
Cmdlet          Set-VMKeyProtector                                 2.0.0.0    Hyper-V
Cmdlet          Set-VMKeyStorageDrive                              2.0.0.0    Hyper-V
Cmdlet          Set-VMMemory                                       2.0.0.0    Hyper-V
Cmdlet          Set-VMMigrationNetwork                             2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapter                               2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapterFailoverConfiguration          2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapterIsolation                      2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapterRdma                           2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapterRoutingDomainMapping           2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapterTeamMapping                    2.0.0.0    Hyper-V
Cmdlet          Set-VMNetworkAdapterVlan                           2.0.0.0    Hyper-V
Cmdlet          Set-VMPartitionableGpu                             2.0.0.0    Hyper-V
Cmdlet          Set-VMProcessor                                    2.0.0.0    Hyper-V
Cmdlet          Set-VMRemoteFx3dVideoAdapter                       2.0.0.0    Hyper-V
Cmdlet          Set-VMReplication                                  2.0.0.0    Hyper-V
Cmdlet          Set-VMReplicationAuthorizationEntry                2.0.0.0    Hyper-V
Cmdlet          Set-VMReplicationServer                            2.0.0.0    Hyper-V
Cmdlet          Set-VMResourcePool                                 2.0.0.0    Hyper-V
Cmdlet          Set-VMSan                                          2.0.0.0    Hyper-V
Cmdlet          Set-VMSecurity                                     2.0.0.0    Hyper-V
Cmdlet          Set-VMSecurityPolicy                               2.0.0.0    Hyper-V
Cmdlet          Set-VMStorageSettings                              2.0.0.0    Hyper-V
Cmdlet          Set-VMSwitch                                       2.0.0.0    Hyper-V
Cmdlet          Set-VMSwitchExtensionPortFeature                   2.0.0.0    Hyper-V
Cmdlet          Set-VMSwitchExtensionSwitchFeature                 2.0.0.0    Hyper-V
Cmdlet          Set-VMSwitchTeam                                   2.0.0.0    Hyper-V
Cmdlet          Set-VMVideo                                        2.0.0.0    Hyper-V
Cmdlet          Start-VM                                           2.0.0.0    Hyper-V
Cmdlet          Start-VMFailover                                   2.0.0.0    Hyper-V
Cmdlet          Start-VMInitialReplication                         2.0.0.0    Hyper-V
Cmdlet          Start-VMTrace                                      2.0.0.0    Hyper-V
Cmdlet          Stop-VM                                            2.0.0.0    Hyper-V
Cmdlet          Stop-VMFailover                                    2.0.0.0    Hyper-V
Cmdlet          Stop-VMInitialReplication                          2.0.0.0    Hyper-V
Cmdlet          Stop-VMReplication                                 2.0.0.0    Hyper-V
Cmdlet          Stop-VMTrace                                       2.0.0.0    Hyper-V
Cmdlet          Suspend-VM                                         2.0.0.0    Hyper-V
Cmdlet          Suspend-VMReplication                              2.0.0.0    Hyper-V
Cmdlet          Test-VHD                                           2.0.0.0    Hyper-V
Cmdlet          Test-VMNetworkAdapter                              2.0.0.0    Hyper-V
Cmdlet          Test-VMReplicationConnection                       2.0.0.0    Hyper-V
Cmdlet          Update-VMVersion                                   2.0.0.0    Hyper-V
Cmdlet          Wait-VM                                            2.0.0.0    Hyper-V

あとがき

Windows10では、Hyper-Vに限らず、多くの動作や設定をPowerShellで実行することができます。普段のWindows10まわりの操作で煩わしさを感じているなら、PowerShellでスクリプト化を検討してみるのもありかもしれませんね。

記事が役立ったらシェアしてくれるとうれしいです。

あなたにおすすめのコンテンツ
トップへ戻る