vSphere PowerCLI Reference

New-HardDisk

Synopsis

Creates a new hard disk on the specified location.

Syntax

New-HardDisk [-AdvancedOption <AdvancedOption[]>] [[-Persistence] <String>] [-Controller <ScsiController>] [[-DiskType] <DiskType>] [-CapacityKB <Int64>] [-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>]

Related Commands

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

Detailed Description

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

NameTypeDescriptionRequired?Pipeline InputDefault Value
VMVirtualMachine[]Specify the virtual machines to which you want to add the new disk.truetrue (ByValue)
PersistenceStringSpecify 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 higher.falsefalse
DiskTypeDiskTypeSpecify 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.falsefalse
AdvancedOptionAdvancedOption[]Specify 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.

The SDRS functionality is experimental.
falsefalse
CapacityKBInt64Specify the capacity of the new virtual disk (in KB). You need to specify this parameter when you create hard disks of type Flat.falsefalse
ConfirmSwitchParameterIf 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.falsefalse$true
ControllerScsiControllerSpecify a SCSI controller to which you want to attach the new hard disk.falsefalse
DatastoreStorageResourceSpecify 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 a SdrsVMDiskAntiAffinityRule object to the AdvancedOption parameter and this will override any existing SdrsVMDiskAntiAffinityRule for the virtual machine.falsefalse
DeviceNameStringSpecify 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 accidentally been masked out. 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 the vSphere SDK for .NET.falsefalse
DiskPathStringSpecify the path to the hard disk.truefalse
ServerVIServer[]Specify the vSphere servers on which you want to run the cmdlet. If no value is given to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.falsefalse
SplitSwitchParameterThis parameter is deprecated and scheduled for removal. Use the StorageFormat instead. Specify 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?.falsefalse
StorageFormatVirtualDiskStorageFormatSpecify the storage format of the new hard disk. The valid values are Thin and Thick.falsefalse
ThinProvisionedSwitchParameterThis parameter is deprecated and scheduled for removal. Use the StorageFormat instead. Indicate 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?.falsefalse
WhatIfSwitchParameterIndicate that the cmdlet is run only to display the changes that would be made and actually no objects are modified.falsefalse

Return Type

HardDisk

Notes

Works only on ESX 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 s upported.

Examples

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

$vm = Get-VM VM  $vm | New-HardDisk -CapacityKB 1000 -Persistence persistent

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

-------------- Example 2 --------------

$deviceName = ($host | 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 -CapacityKB 1024000 -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 -CapacityKB 40000 -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.


Copyright © 1998 - 2011 VMware, Inc. All rights reserved.