New-VHD

New-VHD

Creates one or more new virtual hard disks.

Syntax

Parameter Set: DynamicWithoutSource
New-VHD [-Path] <String[]> [-SizeBytes] <UInt64> [-AsJob] [-BlockSizeBytes <UInt32> ] [-ComputerName <String[]> ] [-Dynamic] [-LogicalSectorSizeBytes <UInt32> ] [-PhysicalSectorSizeBytes <UInt32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: Differencing
New-VHD [-Path] <String[]> [-ParentPath] <String> [[-SizeBytes] <UInt64> ] [-AsJob] [-BlockSizeBytes <UInt32> ] [-ComputerName <String[]> ] [-Differencing] [-PhysicalSectorSizeBytes <UInt32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: DynamicWithSource
New-VHD [-Path] <String[]> -Dynamic -SourceDisk <UInt32> [-AsJob] [-BlockSizeBytes <UInt32> ] [-ComputerName <String[]> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: FixedWithoutSource
New-VHD [-Path] <String[]> [-SizeBytes] <UInt64> -Fixed [-AsJob] [-BlockSizeBytes <UInt32> ] [-ComputerName <String[]> ] [-LogicalSectorSizeBytes <UInt32> ] [-PhysicalSectorSizeBytes <UInt32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: FixedWithSource
New-VHD [-Path] <String[]> -Fixed -SourceDisk <UInt32> [-AsJob] [-BlockSizeBytes <UInt32> ] [-ComputerName <String[]> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Detailed Description

The New-VHD cmdlet creates one or more new virtual hard disks in either VHD format or the newer VHDX format. The file extension you specify determines the format.

Parameters

-AsJob

Runs the cmdlet as a background job.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-BlockSizeBytes<UInt32>

Specifies the block size, in bytes, of the virtual hard disk to be created.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ComputerName<String[]>

Specifies one or more Hyper-V hosts on which the virtual hard disk file(s) are 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.

Aliases

none

Required?

false

Position?

named

Default Value

.

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-LogicalSectorSizeBytes<UInt32>

Specifies the logical sector size, in bytes, of the virtual hard disk to be created. Valid values are 512 and 4096.

Aliases

none

Required?

false

Position?

named

Default Value

512

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ParentPath<String>

Specifies the path to the parent of the differencing disk to be created (this parameter may be specified only for the creation of a differencing disk).

Aliases

none

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path<String[]>

Path to the new virtual hard disk file(s) that is being created as a result of a command. If a filename or relative path is specified, the new virtual hard disk path is calculated relative to the current working directory.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-PhysicalSectorSizeBytes<UInt32>

Specifies the physical sector size, in bytes. Valid values are 512 and 4096.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SizeBytes<UInt64>

The maximum size, in bytes, of the virtual hard disk to be created.

Aliases

none

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-SourceDisk<UInt32>

Specifies the physical disk to be used as the source for the virtual hard disk to be created.

Aliases

Number

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-Differencing

Specifies that a differencing virtual hard disk is to be created.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Dynamic

Specifies that a dynamic virtual hard disk is to be created.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Fixed

Specifies that a fixed virtual hard disk is to be created.

Aliases

none

Required?

true

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (https://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.

  • VHDObject[]

Examples

Example 1

This example creates a dynamic virtual hard disk in VHDX format that is 10 GB in size. The file extension determines the format and the default type of dynamic is used because no type is specified.

PS C:\> New-VHD –Path c:\Base.vhdx –SizeBytes 10GB

Example 2

This example creates a VHDX-format differencing virtual hard disk with a parent path of c:\Base.vhdx.

PS C:\> New-VHD –ParentPath c:\Base.vhdx –Path c:\Diff.vhdx -Differencing

Example 3

This example creates a 1 TB VHD-format fixed virtual hard disk at the specified path. The data for the virtual hard disk is populated from the disk identified in the system by the number 2. You can list the disks attached to the system and the number associated with each disk using the Get-Disk cmdlet.

PS C:\> New-VHD -Path C:\fixed.vhd –Fixed –SourceDisk 2 –SizeBytes 1TB

Example 4

This example creates a new 1 TB VHDX-format dynamic virtual hard disk at the specified path with a block size of 128 MB and a logical sector size of 4 KB.

PS C:\> New-VHD –Path c:\LargeSectorBlockSize.vhdx –BlockSizeBytes 128MB –LogicalSectorSize 4KB –SizeBytes 1TB