Function MyNewVM($vmItem) {
New-VHD -Path $vmItem.VhdVMPath -ParentPath $vmItem.VhdParentPath
New-VM -Name $vmItem.GuestName -Generation $vmItem.Generation -Path $vmItem.osDirBase -MemoryStartupBytes $vmItem.MemoryStartupBytes -VHDPath $vmItem.VhdVMPath -SwitchName $vmItem.SwitchName
Rename-VMNetworkAdapter -VMName $vmItem.GuestName -NewName "eth0"
Set-VMNetworkAdapter -VMName $vmItem.GuestName -Name "eth0" -StaticMacAddress $vmItem.StaticMacAddress
Set-VMMemory -VMName $vmItem.GuestName -DynamicMemoryEnabled 1 -MinimumBytes $vmItem.MemoryMinimumBytes -MaximumBytes $vmItem.MemoryMaximumBytes
Set-VMProcessor -VMName $vmItem.GuestName -Count $vmItem.ProcessorCount -Maximum $vmItem.ProcessorMaximum
}
$baseDir = "C:\Hyper-V\os";
$osName = "os-ft-20240526";
$vmItem=@{}
$vmItem.Generation = 1;
$vmItem.osDirBase = Join-Path -Path $baseDir -ChildPath $osName
$vmItem.VhdParentPath = $osDir + ".vhdx"
$vmItem.SwitchName = "wan"
$vmItem.MemoryStartupBytes = 512MB#启动内存
$vmItem.MemoryMinimumBytes = 512MB#最低内存
$vmItem.MemoryMaximumBytes = 1GB#最大内存
$vmItem.ProcessorCount = 1#CPU核心数
$vmItem.ProcessorMaximum = 100#CPU限制
$vmItem.StaticMacAddress = "00155D010203"
for ($i=2; $i -le 30; $i++) {
$vmItem.GuestName = "ft-" + $i
$vmItem.vmDir = Join-Path -Path $osDirBase -ChildPath $vmItem.GuestName;
$vmItem.VhdVMPath = Join-Path -Path $vmItem.vmDir -ChildPath ($vmItem.GuestName + ".vhdx")
MyNewVM($vmItem)
}
标签:VhdVMPath,Hyper,批量,GuestName,虚拟机,vmItem,Path,VMName,MemoryStartupBytes
From: https://www.cnblogs.com/xiangxisheng/p/18215294