Add-VMHardDiskDrive

Add-VMHardDiskDrive

Adds a hard disk drive to a virtual machine.

Syntax

Parameter Set: VMName
Add-VMHardDiskDrive [-VMName] <String[]> [[-ControllerType] <ControllerType> ] [[-ControllerNumber] <Int32> ] [[-ControllerLocation] <Int32> ] [[-Path] <String> ] [-AllowUnverifiedPaths] [-ComputerName <String[]> ] [-DiskNumber <UInt32> ] [-Passthru] [-ResourcePoolName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: VMDriveController
Add-VMHardDiskDrive [-VMDriveController] <VMDriveController> [[-ControllerLocation] <Int32> ] [[-Path] <String> ] [-AllowUnverifiedPaths] [-ComputerName <String[]> ] [-DiskNumber <UInt32> ] [-Passthru] [-ResourcePoolName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: VMId
Add-VMHardDiskDrive [[-ControllerLocation] <Int32> ] [[-Path] <String> ] [-AllowUnverifiedPaths] [-ComputerName <String[]> ] [-DiskNumber <UInt32> ] [-Passthru] [-ResourcePoolName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: VMObject
Add-VMHardDiskDrive [-VM] <VirtualMachine[]> [[-ControllerType] <ControllerType> ] [[-ControllerNumber] <Int32> ] [[-ControllerLocation] <Int32> ] [[-Path] <String> ] [-AllowUnverifiedPaths] [-ComputerName <String[]> ] [-DiskNumber <UInt32> ] [-Passthru] [-ResourcePoolName <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Detailed Description

The Add-VMHardDiskDrive cmdlet adds a hard disk drive to a virtual machine.

Parameters

-ComputerName<String[]>

Specifies one or more virtual machine hosts on which the hard disk drive is to be added. 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

PSComputerName

Required?

false

Position?

named

Default Value

.

Accept Pipeline Input?

True (ByPropertyName)

Accept Wildcard Characters?

false

-ControllerLocation<Int32>

Specifies the number of the location on the controller at which the hard disk drive is to be added. If not specified, the first available location in the controller specified with the ControllerNumber parameter is used.

Aliases

none

Required?

false

Position?

4

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ControllerNumber<Int32>

Specifies the number of the controller to which the hard disk drive is to be added. If not specified, this parameter assumes the value of the first available controller at the location specified in the ControllerLocation parameter.

Aliases

none

Required?

false

Position?

3

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ControllerType<ControllerType>

Specifies the type of the controller to which the hard disk drive is to be added. If not specified, IDE is attempted first. If the IDE controller port at the specified number and location is already connected to a drive, then it will try to create one on the SCSI controller specified by ControllerNumber. Allowed values are IDE and SCSI.

Aliases

none

Required?

false

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Passthru

Passes the added Microsoft.Virtualization.Powershell.HardDiskDrive object through to the pipeline.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path<String>

Specifies the full path of the hard disk drive file to be added.

Aliases

none

Required?

false

Position?

5

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ResourcePoolName<String>

Specifies the friendly name of the ISO resource pool to which this virtual hard disk is to be associated.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-VM<VirtualMachine[]>

Specifies the virtual machine to which the hard disk drive is to be added.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-VMDriveController<VMDriveController>

Specifies the controller to which the hard disk drive is to be added.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-VMName<String[]>

Specifies the name of the virtual machine to which the hard disk drive is to be added.

Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

True (ByValue)

Accept Wildcard Characters?

false

-AllowUnverifiedPaths

Specifies that no error is to be thrown if the specified path is not verified as accessible by the cluster. This parameter is applicable to clustered virtual machines.

Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DiskNumber<UInt32>

Specifies the disk number of the offline physical hard drive to be connected as a passthrough disk.

Aliases

Number

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

True (ByPropertyName)

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.

  • Microsoft.HyperV.Powershell.DriveController[]
  • Microsoft.HyperV.Powershell.VirtualMachine[]

Outputs

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

  • None by default; Microsoft.Virtualization.Powershell.HardDiskDrive if –PassThru is specified.

Examples

Example 1

Creates a virtual hard disk using file D:\VHDs\disk1.vhdx on virtual machine Test.

PS C:\> Add-VMHardDiskDrive -VMName Test -Path D:\VHDs\disk1.vhdx

Example 2

Adds a virtual hard disk to SCSI controller number 0 on virtual machine Test.

PS C:\> Get-VM Test | Add-VMHardDiskDrive –ControllerType SCSI -ControllerNumber 0

Example 3

This example gets a SSCI controller on a virtual machine named Test and then adds physical disk 2 to that controller.

PS C:\> Get-VMScsiController –VMName Test –Number 0 | Add-VMHardDiskDrive –DiskNumber 2

Example 4

This example gets physical disk 2 and then adds it to a virtual machine named Test.

PS C:\> Get-Disk 2 | Add-VMHardDiskDrive –VMName Test