了解如何使用 Hyper-V 管理員和 Windows PowerShell 建立虛擬機器,以及在您於 Hyper-V 管理員中建立時有哪些選項。
建立虛擬機器
Open Hyper-V Manager.
In the left pane, under Hyper-V Manager, select your server.
From the Actions pane, select New, and then select Virtual Machine.
從 [新增虛擬機精靈]中,選取 [下一步]。
針對每個頁面上的虛擬機器,做出適當的選擇。 如需詳細資訊,請參閱Hyper-V 管理員中的新虛擬機器選項和預設值。
After verifying your choices in the Summary page, select Finish.
In Hyper-V Manager, right-click the virtual machine and select Connect....
In the Virtual Machine Connection window, select Action>Start.
On the Windows desktop, select the Start button and type Windows PowerShell.
Right-click on Windows PowerShell and select Run as administrator.
Get the name of the virtual switch that you want the virtual machine to use by using the Get-VMSwitch cmdlet:
Get-VMSwitch * | Format-Table Name
Use the New-VM cmdlet to create the virtual machine. 請參閱下列範例:
Note
If you move this virtual machine to a Hyper-V host that runs Windows Server 2012 R2, use the -Version parameter with New-VM to set the virtual machine configuration version to 5. Windows Server 2012 R2 或較早版本不支援 Windows Server 2016 的預設虛擬機器設定版本。 建立虛擬機器之後,您便無法變更虛擬機器設定版本。 如需詳細資訊,請參閱支援的虛擬機器設定版本。
現有的虛擬硬碟 - 若要使用現有虛擬硬碟建立虛擬機器,您可以使用下列命令,其中:
-Name is the name that you provide for the virtual machine that you're creating.
-MemoryStartupBytes is the amount of memory that is available to the virtual machine at start up.
-BootDevice is the device that the virtual machine boots to when it starts like the network adapter (NetworkAdapter) or virtual hard disk (VHD).
-VHDPath is the path to the virtual machine disk that you want to use.
-Path is the path to store the virtual machine configuration files.
-Generation is the virtual machine generation. 針對 VHD 使用第 1 代,針對 VHDX 使用第 2 代。 請參閱我應在 Hyper-V 建立第 1 或 2 代的虛擬機器嗎?。
-Switch is the name of the virtual switch that you want the virtual machine to use to connect to other virtual machines or the network. 請參閱為 Hyper-V 虛擬機器建立虛擬交換器。
New-VM -Name <Name> -MemoryStartupBytes <Memory> -BootDevice <BootDevice> -VHDPath <VHDPath> -Path <Path> -Generation <Generation> -Switch <SwitchName>
For example:
New-VM -Name TestVM -MemoryStartupBytes 4GB -BootDevice VHD -VHDPath .\VMs\Test.vhdx -Path .\VMData -Generation 2 -Switch ExternalSwitch
這會建立名為 TestVM 的第 2 代虛擬機器,並有 4 GB 的記憶體。 該虛擬機器會從目前目錄中的 VMs\Test.vhdx 資料夾開機並使用名為 ExternalSwitch 的虛擬交換器。 虛擬機器設定檔會儲存在 VMData 資料夾中。
新的虛擬硬碟 - 若要使用新的虛擬硬碟建立虛擬機,請使用 -NewVHDPath 取代上一個範例中的 -VHDPath 參數,並新增 -NewVHDSizeBytes 參數。 For example,
New-VM -Name TestVM -MemoryStartupBytes 4GB -BootDevice VHD -NewVHDPath .\VMs\Test.vhdx -Path .\VMData -NewVHDSizeBytes 20GB -Generation 2 -Switch ExternalSwitch
開機至操作系統映像的新虛擬硬碟 - 若要使用開機至操作系統映射的新虛擬磁碟建立虛擬機,請參閱在 Windows 上建立 Hyper-V 的虛擬機逐步解說中的 PowerShell 範例。
Start the virtual machine by using the Start-VM cmdlet. 執行下列 Cmdlet,其中 Name 是您建立的虛擬機器名稱:
Start-VM -Name <Name>
For example:
Start-VM -Name TestVM
使用虛擬機器連線 (VMConnect) 以連線至虛擬機器:
VMConnect.exe <ServerName> <VMName>
For example:
VMConnect.exe localhost "TestVM"
Hyper-V 管理員新虛擬機器精靈中的選項
下表列出您在 Hyper-V 管理員中建立虛擬機器時可選擇的選項,以及每個虛擬機器的預設值。
Page |
Windows Server 2016、Windows 10 和更新版本的預設值 |
Other options |
指定名稱和位置 |
名稱:新虛擬機器。 Location: C:\ProgramData\Microsoft\Windows\Hyper-V\. |
您也可以為虛擬機器輸入自己的名稱並選擇其他位置。 這是虛擬機組態檔的儲存位置。 |
Specify Generation |
Generation 1 |
您也可以選擇建立第 2 代虛擬機器。 如需詳細資訊,請參閱我應在 Hyper-V 建立第 1 代或第 2 代的虛擬機器嗎?。 |
Assign Memory |
啟動記憶體:1024 MB Dynamic memory: not selected |
您可以將啟動記憶體從 32 MB 設定為 5902 MB。 您也可以選擇使用動態記憶體。 如需詳細資訊,請參閱 Hyper-V 動態記憶體概觀。 |
Configure Networking |
Not connected |
您可以從現有虛擬交換器清單中選取虛擬機器的網路連線。 請參閱為 Hyper-V 虛擬機器建立虛擬交換器。 |
連線虛擬硬碟 |
建立虛擬硬碟 Name: <vmname>.vhdx
Location: C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\
Size: 127 GB |
您也可以選擇使用現有的虛擬硬碟,或稍後再連結虛擬硬碟。 |
Installation Options |
稍後安裝作業系統 |
這些選項會變更虛擬機器的開機順序,讓您可以透過 .iso 檔案、可開機的軟磁碟或網路安裝服務 (例如 Windows 部署服務 (WDS)) 進行安裝。 |
Summary |
顯示您選擇的選項,以便確認它們正確無誤。 - Name - Generation - Memory - Network - 硬碟 - 作業系統 |
Tip: You can copy the summary from the page and paste it into e-mail or somewhere else to help you keep track of your virtual machines. |
Related content