Syntax
New-HardDisk [-VM] <VirtualMachine> [[-Persistence] <String>] [[-DiskType] <DiskType>] [-AdvancedOption <AdvancedOption[]>] [-CapacityGB <Decimal>] [-CapacityKB <Int64>] [-Controller <ScsiController>] [-Datastore <StorageResource>] [-DeviceName <String>] [-Server <VIServer[]>] [-Split] [-StorageFormat <VirtualDiskStorageFormat>] [-ThinProvisioned] [-KmsCluster <KmsCluster>] [-StoragePolicy <StoragePolicy>] [-Confirm] [-WhatIf] [<CommonParameters>]Related Commands
Online VersionDetailed 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 that 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 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 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 Logical Unit Number (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 by using the PowerCLI views. | false | False | |
DiskPath | String | Specifies the path to the hard disk. | true | False | |
KmsCluster | KmsCluster | Specifies the KmsCluster that you use to generate a key for encryption during creating the new disk. If StoragePolicy is not specified then the default encryption storage policy "VM Encryption Policy" is used. | false | 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 cmdlet. | 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 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". | false | False | |
StorageFormat | VirtualDiskStorageFormat | Specifies the storage format of the new hard disk. This parameter accepts Thin, Thick, and EagerZeroedThick values. | false | False | |
StoragePolicy | StoragePolicy | Specifies the storage policy that you want to attach to the new disk. If the storage policy is an encryption policy, the new disk will be encrypted. If the storage policy is a non-encryption policy, the policy will be attached to the new disk. | 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 that 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 objectsNotes
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. KmsCluster and StoragePolicy work only on vCenter Server systems. To create an encrypted hard disk to a virtual machine, there are several requirements: 1) The virtual machine should be encrypted before running New-HardDisk. 2) The virtual machine should be powered off.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 --------------------------
$kmsCluster = Get-KmsCluster | select -first 1 New-HardDisk -VM $vm -CapacityGB 100 -KmsCluster $kmsCluster
Creates an encrypted hard disk by using the specified kmsCluster to generate the key for encryption
-------------------------- 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 will be 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
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 8 --------------------------
New-HardDisk -VM $vm -VDisk $vDisk
Attaches the $vDisk VDisk object to the $vm virtual machine.