New-VM

New-VM

Creates a new virtual machine.

語法

Parameter Set: No VHD
New-VM [[-Name] <String> ] [[-MemoryStartupBytes] <Int64]> ] [[-Generation] <Int16]> {1 | 2} ] [-AsJob] [-BootDevice <BootDevice]> ] [-CimSession <Microsoft.Management.Infrastructure.CimSession[]> ] [-ComputerName <String[]> ] [-Credential <System.Management.Automation.PSCredential[]> ] [-NoVHD] [-Path <String> ] [-SwitchName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: Existing VHD
New-VM [[-Name] <String> ] [[-MemoryStartupBytes] <Int64]> ] [[-Generation] <Int16]> {1 | 2} ] -VHDPath <String> [-AsJob] [-BootDevice <BootDevice]> ] [-CimSession <Microsoft.Management.Infrastructure.CimSession[]> ] [-ComputerName <String[]> ] [-Credential <System.Management.Automation.PSCredential[]> ] [-Path <String> ] [-SwitchName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: New VHD
New-VM [[-Name] <String> ] [[-MemoryStartupBytes] <Int64]> ] [[-Generation] <Int16]> {1 | 2} ] -NewVHDPath <String> -NewVHDSizeBytes <UInt64> [-AsJob] [-BootDevice <BootDevice]> ] [-CimSession <Microsoft.Management.Infrastructure.CimSession[]> ] [-ComputerName <String[]> ] [-Credential <System.Management.Automation.PSCredential[]> ] [-Path <String> ] [-SwitchName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

詳細描述

The New-VM cmdlet creates a new virtual machine.

參數

-AsJob

Runs the cmdlet as a background job.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-BootDevice<BootDevice]>

Specifies the device to use as the boot device for the new virtual machine. Allowed values are CD, Floppy, LegacyNetworkAdapter, IDE, NetworkAdapter, and VHD.

When LegacyNetworkAdapter is specified, this configures the new virtual machine with a network adapter that can be used to perform a PXE boot and install an operating system from a network installation server.

Note: Generation 2 virtual machines do not support Floppy, LegacyNetworkAdapter or IDE. Using these values with a Generation 2 virtual machine will cause an error.

VHD and NetworkAdapter are new to Generation 2 virtual machines. If you specify them on a Generation 1 virtual machine, then they are interpreted to be IDE and LegacyNetworkAdapter, respectively.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-CimSession<Microsoft.Management.Infrastructure.CimSession[]>

在遠端工作階段或遠端電腦上執行 Cmdlet。輸入電腦名稱或工作階段物件,例如 New-CimSessionGet-CimSession Cmdlet 的輸出。預設為本機電腦上目前的工作階段。

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-ComputerName<String[]>

Specifies one or more Hyper-V hosts on which the virtual machine is to be created. NetBIOS names, IP addresses, and fully qualified domain names are allowable. The default is the local computer. Use localhost or a dot (.) to specify the local computer explicitly.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-Credential<System.Management.Automation.PSCredential[]>

Specifies one or more user accounts that have permission to perform this action. The default is the current user.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-Generation<Int16]>

Specifies the generation, as an integer, for the virtual machine. The values that are valid in this version of Windows are 1 and 2.

別名

none

必要項?

false

位置?

3

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-MemoryStartupBytes<Int64]>

Specifies the amount of memory, in bytes, to assign to the virtual machine. The default value is 512 MB.

別名

none

必要項?

false

位置?

2

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-Name<String>

Specifies the name of the new virtual machine. The default name is New virtual machine.

別名

VMName

必要項?

false

位置?

1

預設值

none

接受管線輸入?

True (ByValue, ByPropertyName)

接受萬用字元?

false

-NewVHDPath<String>

Creates a new virtual hard disk with the specified path and connects it to the new virtual machine. Absolute paths are allowed. If only a file name is specified, the virtual hard disk is created in the default path configured for the host.

別名

none

必要項?

true

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-NoVHD

Creates a virtual machine without attaching any virtual hard disks.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-Path<String>

Specifies the directory to store the files for the new virtual machine.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-SwitchName<String>

Specifies the friendly name of the virtual switch if you want to connect the new virtual machine to an existing virtual switch to provide connectivity to a network. Hyper-V automatically creates a virtual machine with one virtual network adapter, but connecting it to a virtual switch is optional.

別名

none

必要項?

false

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-VHDPath<String>

Specifies the path to a virtual hard disk file.

別名

none

必要項?

true

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-NewVHDSizeBytes<UInt64>

Specifies the size of the dynamic virtual hard disk that is created and attached to the new virtual machine.

別名

none

必要項?

true

位置?

named

預設值

none

接受管線輸入?

false

接受萬用字元?

false

-Confirm

在執行指令程式之前提示您確認。

必要項?

false

位置?

named

預設值

false

接受管線輸入?

false

接受萬用字元?

false

-WhatIf

示範當執行指令程式時會發生什麼事情。此指令程式並未執行。

必要項?

false

位置?

named

預設值

false

接受管線輸入?

false

接受萬用字元?

false

<CommonParameters>

這個指令程式支援一般參數:-Verbose、-Debug、-ErrorAction、-ErrorVariable、-OutBuffer 和 -OutVariable。如需詳細資訊,請參閱 about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216)。

輸入

輸入類型是可透過管道傳送至指令程式的物件類型。

輸出

輸出類型是指令程式所發出的物件類型。

  • Microsoft.HyperV.PowerShell.VirtualMachine

範例

Example 1

This example creates a new virtual machine named new 1 that has 512 MB of memory.

PS C:\> New-VM –Name "new 1" –MemoryStartupBytes 512MB

Example 2

This example creates a virtual machine named new 2 that has 1 GB of memory and that is connected to a new 40 GB virtual hard disk that uses the VHDX format.

PS C:\> New-VM –Name "new 2" –MemoryStartupBytes 1GB –NewVHDPath d:\vhd\base.vhdx

Example 3

This example creates a virtual machine named new 3 that has 1 GB of memory and connects it to an existing virtual hard disk that uses the VHDX format.

PS C:\> New-VM –Name "new 3" –MemoryStartupBytes 1GB –VHDPath d:\vhd\BaseImage.vhdx