編集

次の方法で共有


New-VHD

Creates one or more new virtual hard disks.

Syntax

New-VHD
   [-Path] <String[]>
   [-SizeBytes] <UInt64>
   [-Dynamic]
   [-BlockSizeBytes <UInt32>]
   [-LogicalSectorSizeBytes <UInt32>]
   [-PhysicalSectorSizeBytes <UInt32>]
   [-AsJob]
   [-CimSession <CimSession[]>]
   [-ComputerName <String[]>]
   [-Credential <PSCredential[]>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-VHD
   [-Path] <String[]>
   [-ParentPath] <String>
   [[-SizeBytes] <UInt64>]
   [-Differencing]
   [-BlockSizeBytes <UInt32>]
   [-PhysicalSectorSizeBytes <UInt32>]
   [-AsJob]
   [-CimSession <CimSession[]>]
   [-ComputerName <String[]>]
   [-Credential <PSCredential[]>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-VHD
   [-Path] <String[]>
   [-SizeBytes] <UInt64>
   [-Fixed]
   [-BlockSizeBytes <UInt32>]
   [-LogicalSectorSizeBytes <UInt32>]
   [-PhysicalSectorSizeBytes <UInt32>]
   [-AsJob]
   [-CimSession <CimSession[]>]
   [-ComputerName <String[]>]
   [-Credential <PSCredential[]>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-VHD
   [-Path] <String[]>
   -SourceDisk <UInt32>
   [-Fixed]
   [-BlockSizeBytes <UInt32>]
   [-AsJob]
   [-CimSession <CimSession[]>]
   [-ComputerName <String[]>]
   [-Credential <PSCredential[]>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
New-VHD
   [-Path] <String[]>
   -SourceDisk <UInt32>
   [-Dynamic]
   [-BlockSizeBytes <UInt32>]
   [-AsJob]
   [-CimSession <CimSession[]>]
   [-ComputerName <String[]>]
   [-Credential <PSCredential[]>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

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

Examples

Example 1

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

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

Example 2

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

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

Example 3

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

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.

Example 4

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

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.

Example 5

PS C:\> $vhdpath = "C:\VHDs\Test.vhdx"
PS C:\> $vhdsize = 127GB
PS C:\> New-VHD -Path $vhdpath -Dynamic -SizeBytes $vhdsize | Mount-VHD -Passthru |Initialize-Disk -Passthru |New-Partition -AssignDriveLetter -UseMaximumSize |Format-Volume -FileSystem NTFS -Confirm:$false -Force

This example creates a new 127GB VHD and then mounts, initializes, and formats it so the drive is ready to use.

Parameters

-AsJob

Runs the cmdlet as a background job.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-BlockSizeBytes

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

Type:UInt32
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-CimSession

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

Type:CimSession[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ComputerName

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.

Type:String[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Credential

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

Type:PSCredential[]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Differencing

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

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Dynamic

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

Type:SwitchParameter
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Fixed

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

Type:SwitchParameter
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-LogicalSectorSizeBytes

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

Type:UInt32
Accepted values:512, 4096
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ParentPath

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).

Type:String
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Path

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.

Type:String[]
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-PhysicalSectorSizeBytes

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

Type:UInt32
Accepted values:512, 4096
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-SizeBytes

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

Type:UInt64
Position:1
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-SourceDisk

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

Type:UInt32
Aliases:Number
Position:Named
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

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

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Outputs

Microsoft.Vhd.PowerShell.VirtualHardDisk