1 Enable Hyper-V
Enable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -All
2 Create virtual switch
$NetNetAdapter = (Get-NetAdapter)[0]
New-VMSwitch -Name 'External Virtual Network Switch' -NetAdapterName $NetNetAdapter.Name -AllowManagementOS $TRUE
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/connect-to-network
https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vmswitch?view=win10-ps
3 Create virtual hard disk
$VHDFilePath = 'd:\test.vhdx'
New-VHD -Path $VHDFilePath -Dynamic -SizeBytes 32GB
https://docs.microsoft.com/en-us/powershell/module/hyper-v/new-vhd?view=win10-ps
4 Create virtual machine
$VMName = 'test_vm'
$VMPath = "d:\$VMName"
$VMSwitch = 'External Virtual Network Switch'
$InstallMedia = 'd:\en_windows_server_2016_x64_dvd_9718492.iso'
$VHDFilePath = 'd:\test.vhdx'
# Create New Virtual Machine
New-VM -Name $VMName -Generation 2 -VHDPath $VHDFilePath -SwitchName $VMSwitch -MemoryStartupBytes 2147483648 -Path $VMPath
# Add DVD Drive to Virtual Machine
Add-VMScsiController -VMName $VMName
Add-VMDvdDrive -VMName $VMName -ControllerNumber 1 -ControllerLocation 0 -Path $InstallMedia
# Mount Installation Media
$DVDDrive = Get-VMDvdDrive -VMName $VMName
# Configure Virtual Machine to Boot from DVD
Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive
5 参考引用
https://docs.microsoft.com/en-us/virtualization/index#pivot=main&panel=server
https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/hyper-v-on-windows-server