在Hyper-V中用Cmdlets快速创建Virtual Machine

本文介绍了如何利用Hyper-V 3.0与PowerShell 3.0,通过New-VHD和New-VM命令行工具,高效地创建虚拟机。通过示例展示了创建动态和固定大小的VHD/VHDX,以及配置差异磁盘和启动虚拟机的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[注:该文章发行于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状态了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值