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.
New-HardDisk
-VM < VirtualMachine >
[ [-Persistence ] < String > ]
[ [-DiskType ] < DiskType > ]
[-AdvancedOption < AdvancedOption[] > ]
[-CapacityGB < Decimal > ]
[-CapacityKB < Int64 > ]
[-Controller < ScsiController > ]
[-Datastore < StorageResource > ]
[-DeviceName < String > ]
[-KeyProvider < KeyProvider > ]
[-ProgressAction < ActionPreference > ]
[-Server < VIServer[] > ]
[-Split ]
[-StorageFormat < VirtualDiskStorageFormat > ]
[-StoragePolicy < StoragePolicy > ]
[-ThinProvisioned ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
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 Persistence String 1
Specifies the disk persistence mode. The valid values are Persistent, NonPersistent, IndependentPersistent, IndependentNonPersistent, and Undoable. This parameter is supported only when the disk type is set to "rawVirtual" or "flat". The 'NonPersistent' and 'Undoable' values are deprecated and scheduled for removal. Their use is not recommended because they do not work with snapshots and are not supported on ESX 3.5 and later.
optional DiskType DiskType 2
Specifies the type of file backing that you want to use. The valid values are rawVirtual, rawPhysical, flat, PMem, and unknown. 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.
optional AdvancedOption AdvancedOption[] named
Specifies advanced options for creating hard disks. Accepts only SdrsVMDiskAntiAffinityRule objects. You can define an anti-affinity Storage Distributed Resource Scheduler (SDRS) rule for the disk by specifying a SdrsVMDiskAntiAffinityRule object to the AdvancedOption parameter and this will override any existing SdrsVMDiskAntiAffinityRule for the virtual machine. The SdrsVMDiskAntiAffinityRule defines a Storage DRS intra-VM anti-affinity rule (VM disk anti-affinity rule). It is only applicable when creating a virtual machine or hard disk on a datastore cluster. An instance of the object is created by invoking its constructor. There are two constructors - "public SdrsVMDiskAntiAffinityRule(param string[] diskIdentifier)" and "public SdrsVMDiskAntiAffinityRule(param HardDisk[] disk)". For the first constructor, "diskIdentifier" can be either the disk key or the index of the disk in the disk array. The specified disks (and the disk to which the rule is applied) are placed in an anti-affinity rule on a DatastoreCluster. Only one such rule is supported per virtual machine. You can pass the instance to the AdvancedOption parameter of the New-VM or New-HardDisk cmdlets.
optional CapacityGB Decimal named
Specifies the capacity of the new virtual disk in gigabytes (GB). You need to specify this parameter when you create hard disks of type Flat.
optional CapacityKB Int64 named
This parameter is obsolete. Use the CapacityGB parameter instead. Specifies the capacity of the new virtual disk in kilobytes (KB). You need to specify this parameter when you create hard disks of type Flat.
optional Controller ScsiController named
Specifies a SCSI controller to which you want to attach the new hard disk.
optional Datastore StorageResource named
  • wildcards
Specifies the datastore where you want to place the new hard disk. If a DatastoreCluster object is passed to the Datastore parameter, the hard disk is added to the DatastoreCluster in an automated SDRS mode. You can define an anti-affinity SDRS rule for the disk by specifying an SdrsVMDiskAntiAffinityRule object to the AdvancedOption parameter and this will override any existing SdrsVMDiskAntiAffinityRule for the virtual machine.
optional DeviceName String named
Specifies the host-specific device the Logical Unit Number (LUN) is being accessed through. If the target LUN is not available on the host, then it's empty. For example, this might happen if it is masked out accidentally. Only supported when DiskType is set to "rawVirtual" or "rawPhysical". The device name is visible in the vSphere Client through the new raw hard disk wizard or you can retrieve it by using the PowerCLI views.
optional KeyProvider KeyProvider named
Specifies the key provider that you want to use for the encryption key while creating the new hard disk. If the StoragePolicy parameter is not specified, the default encryption storage policy "VM Encryption Policy" is used.
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.
optional Split SwitchParameter named
This parameter is deprecated and scheduled for removal. Use the StorageFormat parameter instead. Specifies the type of the virtual disk file - split or monolithic. If the value is $true, the virtual disk is stored in multiple files, each 2 sGB. If the value is $false, the virtual disk is stored in a single file. This parameter is supported only if the DiskType parameter is set to "flat".
optional StorageFormat VirtualDiskStorageFormat named
Specifies the storage format of the new hard disk. This parameter accepts Thin, Thick, and EagerZeroedThick values.
optional StoragePolicy StoragePolicy named
Specifies the storage policy that you want to attach to the new disk. If the storage policy is a PMem policy, the new disk is created in the PMem datastore of the virtual machine host. If the storage policy is an encryption policy, the new disk is encrypted. If the storage policy is a non-encryption policy, the policy is attached to the new disk.
optional ThinProvisioned SwitchParameter named
This parameter is deprecated and scheduled for removal. Use the StorageFormat parameter instead. Indicates to the underlying file system that the virtual disk backing file should be allocated lazily (using thin provisioning). This parameter is only used for file systems that support configuring the provisioning policy on a per file basis, such as VMFS3. This parameter is supported only if the DiskType parameter is set to "flat".
New-HardDisk
-DiskPath < String >
-VM < VirtualMachine >
[ [-Persistence ] < String > ]
[-Controller < ScsiController > ]
[-ProgressAction < ActionPreference > ]
[-Server < VIServer[] > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
DiskPath String named
Specifies the path to the hard disk.
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 Persistence String 1
Specifies the disk persistence mode. The valid values are Persistent, NonPersistent, IndependentPersistent, IndependentNonPersistent, and Undoable. This parameter is supported only when the disk type is set to "rawVirtual" or "flat". The 'NonPersistent' and 'Undoable' values are deprecated and scheduled for removal. Their use is not recommended because they do not work with snapshots and are not supported on ESX 3.5 and later.
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].ConsoleDeviceName

New-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 1
New-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 1
New-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' $disk

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