使用PowerShell创建Hpyer-V虚拟机

#宿主机为Server2012R2,请先手动创建虚拟交换机onboard88,基于母盘创建差异虚拟磁盘,二代虚拟机,动态内存。创建多台虚拟机请修改变量$VMName后重复执行。

$VMName = "s11"

$ParentVMPath = "D:"

$ParentVHDPath = "C:\VM\MotherVHD.vhdx"

$VmPath = $ParentVMPath + "\$VMName"

$VMVHDPath = $VmPath + "\Virtual Hard Disks"

New-Item $VMVHDPath -ItemType directory

New-VHD -ParentPath $ParentVHDPath -Path "$VMVHDPath\$VMName.vhdx" -Differencing

New-VM -Name "$VMName" -MemoryStartupBytes 3GB -Generation 2 -VHDPath "$VMVHDPath\$VMName.vhdx" -SwitchName "onboard88" -Path "$ParentVMPath"

Set-VM -Name $VMName -DynamicMemory -MemoryMinimumBytes 512MB -MemoryMaximumBytes 6GB -ProcessorCount 4

Add-VMDvdDrive -VMName $VMName


你可能感兴趣的:(虚拟机,powershell,hpyer-v)