New-HardDisk Command | Vmware PowerCLI Reference

New-HardDisk

This cmdlet creates a new hard disk on the specified virtual machine or datastore. When a new virtual disk with raw disk mapping (RDM) backing is created, the compatibility mode of "virtual" or "physical" must be specified using the DiskType parameter. In "virtual" compatibility mode, the disk can use the specified disk modes. In "physical" compatibility mode, the disk modes are ignored and commands are passed directly to the backing Logical Unit Number (LUN). If "flat" mode is set by the DiskType parameter, the virtual disk backing is preallocated. If the hard disk is attached to no virtual machine, the value of the DiskType parameter might be Unknown, which means that no type is specified. Use the Persistence parameter to make the disk Persistent (changes are immediately and permanently written to the disk), Nonpersistent (changes to the disk are discarded when you power off or reset the virtual machine), IndependentPersistent, IndependentNonPersistent, or Undoable.

Syntax

New-HardDisk
-VDisk < VDisk >
-VM < VirtualMachine >
[-Controller < ScsiController > ]
[-ProgressAction < ActionPreference > ]
[-Server < VIServer[] > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VDisk VDisk named
  • pipeline
Specifies the VDisk object that you want to attach to the virtual machine.
required
VM VirtualMachine named
  • pipeline
  • wildcards
Specifies the virtual machine to which you want to add the new disk. Passing multiple values to this parameter is obsolete.
optional Controller ScsiController named
Specifies a SCSI controller to which you want to attach the new hard disk.
optional ProgressAction ActionPreference named
optional Server VIServer[] named
  • wildcards
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.

Output

VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDisk

Examples

Example 1

$vm = Get-VM VM$vm | New-HardDisk -CapacityGB 100 -Persistence persistent

Adds a new hard disk to the VM virtual machine in a persistent mode with capacity of 100 GB.

Example 2

$deviceName = ($vmhost | Get-ScsiLun | Where {$_.CanonicalName -match "naa"})[0].ConsoleDeviceNameNew-HardDisk -VM $vm -DiskType RawPhysical -DeviceName $deviceName

Obtains a valid device name for Raw Disk Mapping. Then the command creates an RDM hard disk for the specified virtual machine with the obtained device name.

Example 3

New-HardDisk -VM $vm -CapacityGB 100 -Persistence IndependentNonPersistent

Creates a non-persistent hard disk with the specified capacity.

Example 4

$keyprovider = Get-KeyProvider | select -first 1New-HardDisk -VM $vm -CapacityGB 100 -KeyProvider $keyprovider

Creates an encrypted hard disk by using the specified key provider for the encryption key.

Example 5

$storagepolicy = Get-SpbmStoragePolicy | select -first 1New-HardDisk -VM $vm -CapacityGB 100 -StoragePolicy $storagepolicy

Creates a hard disk with the specified storage policy attached. If the $storagepolicy.IsVAIOFilterEncryptionCapable() is true, the hard disk is encrypted.

Example 6

New-HardDisk -VM $vm -DiskPath "[storage1] OtherVM/OtherVM.vmdk"

Attaches an available disk from a *.vmdk file.

Example 7

$vm = Get-VM WebServerVM$disk = $vm | Get-HardDisk$antiAffinityRule = New-Object 'VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMDiskAntiAffinityRule' $diskNew-HardDisk -VM $vm -AdvancedOption $antiAffinityRule -CapacityGB 40 -Datastore DatastoreCluster1

Retrieves the existing disk which is a part of the VMDK anti-affinity rule, then creates an object describing the rule and a new hard disk with the rule object.

Example 8

New-HardDisk -VM $vm -VDisk $vDisk

Attaches the $vDisk VDisk object to the $vm virtual machine.

Example 9

$vm = Get-VM VM$vm | New-HardDisk -CapacityGB 100 -DiskType PMem

Adds a new hard disk to the VM virtual machine in the PMem datastore of the virtual machine host with capacity of 100 GB.

Related Commands

HardDisk

Copies a virtual hard disk to another destination.

This cmdlet retrieves the virtual hard disks available on a vCenter Server system.

This cmdlet moves a hard disk from one location to another.

This cmdlet creates a new hard disk on the specified location.

This cmdlet removes the specified virtual hard disks.

This cmdlet modifies the properties of the specified virtual hard disk.