[注:该文章发行于Beta版本,不保证长期有效性,如有变更以实际最终版本为准]
在以往我们创建Virutal Machine时更多的可能是依靠GUI模式手动创建,如果需要创建大批量的环境将增加很多工作量。
现在在Hyper-V 3.0与PowerShell 3.0的支持背景下,一切变的更加方便了,我们可以通过New-VHD以及New-VM这两个命令来搭配使用。首先我们先来看看这两个命令的大致使用帮助如下:
NAME
New-VHD
SYNTAX
New-VHD [-Path] <string[]> [-SizeBytes] <UInt64> -Dynamic [-AsJob] [-BlockSizeBytes <UInt32>]
[-LogicalSectorSizeBytes <UInt32>] [-VHDFormat <VhdFormat> {VHD | VHDX}] [-ComputerName <string[]>] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-VHD [-Path] <string[]> -SourceDisk <UInt32> -Dynamic [-AsJob] [-BlockSizeBytes <UInt32>]
[-LogicalSectorSizeBytes <UInt32>] [-VHDFormat <VhdFormat> {VHD | VHDX}] [-ComputerName <string[]>] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-VHD [-Path] <string[]> -SourceDisk <UInt32> -Fixed [-AsJob] [-BlockSizeBytes <UInt32>]
[-LogicalSectorSizeBytes <UInt32>] [-VHDFormat <VhdFormat> {VHD | VHDX}] [-ComputerName <string[]>] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-VHD [-Path] <string[]> [-SizeBytes] <UInt64> -Fixed [-AsJob] [-BlockSizeBytes <UInt32>]
[-LogicalSectorSizeBytes <UInt32>] [-VHDFormat <VhdFormat> {VHD | VHDX}] [-ComputerName <string[]>] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-VHD [-Path] <string[]> [-ParentPath] <string> [-SizeBytes] <UInt64> [-Differencing] [-AsJob] [-BlockSizeBytes
<UInt32>] [-LogicalSectorSizeBytes <UInt32>] [-VHDFormat <VhdFormat> {VHD | VHDX}] [-ComputerName <string[]>]
[-WhatIf] [-Confirm] [<CommonParameters>]
-----------------------------------------------------------------------------------
NAME
New-VM
SYNTAX
New-VM [[-Name] <string>] [[-MemoryStartupBytes] <long>] [-BootDevice <string> {CDRom | Floppy | Network |
HardDrive}] [-NoVHD] [-SwitchName <string>] [-Path <string>] [-AsJob] [-ComputerName <string[]>] [-WhatIf]
[-Confirm] [<CommonParameters>]
New-VM [[-Name] <string>] [[-MemoryStartupBytes] <long>] -NewVHDPath <string> -NewVHDSizeBytes <UInt64>
[-BootDevice <string> {CDRom | Floppy | Network | HardDrive}] [-SwitchName <string>] [-Path <string>] [-AsJob]
[-ComputerName <string[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-VM [[-Name] <string>] [[-MemoryStartupBytes] <long>] -VHDPath <string> [-BootDevice <string> {CDRom | Floppy |
Network | HardDrive}] [-SwitchName <string>] [-Path <string>] [-AsJob] [-ComputerName <string[]>] [-WhatIf]
[-Confirm] [<CommonParameters>]
下面我们先用New-VHD创建一个VHDX,母盘路径指定到之前我们所做的WIN8镜像文件,并标示为Differencing差异磁盘。
在使用New-VM cmdlet来创建一个Virtual Machine,同时指定好之前我们创建的VHDX路径,New-VM包含许多参数,可以自定义内存大小,网卡,等等。
这里我们调用一个额外的cmdlet就是启动之前我们创建好的VM,不得不说Hyper-V 3.0的强大,基本讲所有GUI操作都衍生为一个个实用的Cmdlet。
最后我们查看下,已经为Running状态了。