## PowerCLI Reference

# New-HardDisk

## Synopsis

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

Syntax

New-HardDisk [-AdvancedOption <AdvancedOption[]>] [[-Persistence] <String>] [-Controller <ScsiController>] [[-DiskType] <DiskType>] [-CapacityKB <Int64>] [-CapacityGB <Decimal>] [-Split] [-ThinProvisioned] [-StorageFormat <VirtualDiskStorageFormat>] [-DeviceName <String>] [-Datastore <StorageResource>] [-VM] <VirtualMachine> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-HardDisk [[-Persistence] <String>] [-Controller <ScsiController>] -DiskPath <String> [-VM] <VirtualMachine> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
New-HardDisk [-Controller <ScsiController>] -VDisk <VDisk> [-VM] <VirtualMachine> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Related Commands

Online version
Copy-HardDisk
Get-HardDisk
Remove-HardDisk
Set-HardDisk
Move-HardDisk

Detailed Description

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 pre-allocated. 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.

Parameters

Name | Type | Description | Required? | Pipeline Input | Default Value
--- | --- | --- | --- | --- | ---
VM | VirtualMachine | Specifies the virtual machine to which you want to add the new disk. Passing multiple values to this parameter is obsolete. | true | true (ByValue)
Persistence | String | 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 usage is not recommended because they do not work with snapshots and are not supported on ESX 3.5 and later. | false | false
DiskType | DiskType | Specifies the type of file backing you want to use. The valid values are rawVirtual, rawPhysical, flat, 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. | false | false
AdvancedOption | AdvancedOption[] | Specifies advanced options for creating hard disks. Accepts only SdrsVMDiskAntiAffinityRule objects. You can define an anti-affinity 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 a virtual machine. You can pass the instance to the AdvancedOption parameter of the New-VM or New-HardDisk cmdlets. | false | false
CapacityGB | Decimal | 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. | false | false
CapacityKB | Int64 | This parameter is obsolete. Use CapacityGB 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. | false | false
Confirm | SwitchParameter | If the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false, the cmdlet runs without asking for user confirmation. | false | false
Controller | ScsiController | Specifies a SCSI controller to which you want to attach the new hard disk. | false | false
Datastore | StorageResource | 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. | false | false
DeviceName | String | Specifies the host-specific device the LUN is being accessed through. If the target LUN is not available on the host then it is empty. For example, this could happen if it has been 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 can be retrieved using PowerCLI views. | false | false
DiskPath | String | Specifies the path to the hard disk. | true | false
Server | VIServer[] | Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer. | false | false
Split | SwitchParameter | This parameter is deprecated and scheduled for removal. Use the StorageFormat 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 2GB. 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?. | false | false
StorageFormat | VirtualDiskStorageFormat | Specifies the storage format of the new hard disk. This parameter accepts Thin, Thick, and EagerZeroedThick values. | false | false
ThinProvisioned | SwitchParameter | This parameter is deprecated and scheduled for removal. Use the StorageFormat 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?. | false | false
VDisk | VDisk | Specifies the VDisk object you want to attach to the virtual machine. | true | true (ByValue)
WhatIf | SwitchParameter | Indicates that the cmdlet is run only to display the changes that would be made and actually no objects are modified. | false | false

Return Type

The one or more newly created HardDisk objects

Notes

Works only on ESXi hosts. New-HardDisk cannot create undoable disks on powered-on virtual machines. On ESX versions later than 3.0, non-persistent and undoable disks are not supported.

Examples

-------------- Example 1 --------------

    $vm = Get-VM VM

    $vm | New-HardDisk -CapacityGB 100 -Persistence persistent

Adds to the VM virtual machine a new hard disk 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 a 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 --------------

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

Attaches an available disk from a *.vmdk file.

-------------- Example 5 --------------

    $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

First retrieves the existing disk which will be part of the VMDK anti-affinity rule. Then, creates an object describing the rule and creates the new hard disk.

-------------- Example 6 --------------

    New-HardDisk -VM $vm -VDisk $vDisk

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

Copyright © VMware, Inc. All rights reserved.