powershellscripts.com

Tutorials  PowerShell Cmdlet Help for New-HardDisk



NAME
New-HardDisk

SYNOPSIS
Creates a new hard disk on the specified location.

SYNTAX
New-HardDisk [-AdvancedOption ] [[-Persistence] ] [-Controller ] [[-DiskT
ype] ] [-CapacityKB ] [-Split] [-ThinProvisioned] [-StorageFormat ] [-De
viceName ] [-Datastore ] [-VM] [-Server ] [-WhatIf] [-Confi
rm] []

New-HardDisk [[-Persistence] ] [-Controller ] -DiskPath [-VM] [
-Server ] [-WhatIf] [-Confirm] []


DESCRIPTION
Creates a new hard disk on the specified virtual machine or datastore. When a new virtual disk with raw disk mappin
g (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 "fla
t" 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), Independ
entPersistent, IndependentNonPersistent, or Undoable.


PARAMETERS
-AdvancedOption
Specify advanced options for creating hard disks. Accepts only SdrsVMDiskAntiAffinityRule objects. You can defi
ne an anti-affinity SDRS rule for the disk by specifying a SdrsVMDiskAntiAffinityRule object to the AdvancedOpt
ion 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 o
bject is created by invoking its constructor. There are two constructors - "public SdrsVMDiskAntiAffinityRule(p
aram string[] diskIdentifier)" and "public SdrsVMDiskAntiAffinityRule(param HardDisk[] disk)". For the first co
nstructor, "diskIdentifier" can be either the disk key or the index of the disk in the disk array. The specifie
d 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 paramete
r of the New-VM or New-HardDisk cmdlets.

The SDRS functionality is experimental.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Persistence
Specify the disk persistence mode. The valid values are Persistent, NonPersistent, IndependentPersistent, Indep
endentNonPersistent, and Undoable. This parameter is supported only when the disk type is set to "rawVirtual" o
r "flat". The 'NonPersistent' and 'Undoable' values are deprecated and scheduled for removal. Their usage is no
t recommended because they do not work with snapshots and are not supported on ESX 3.5 and higher.

Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Controller
Specify a SCSI controller to which you want to attach the new hard disk.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-DiskType
Specify the type of file backing you want to use. The valid values are rawVirtual, rawPhysical, flat, and unkno
wn. If the hard disk is attached to no virtual machine, the value of the DiskType parameter might be Unknown, w
hich means that no type is specified.

Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false

-CapacityKB
Specify the capacity of the new virtual disk (in KB). You need to specify this parameter when you create hard d
isks of type Flat.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Split
This 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, e
ach 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".

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-ThinProvisioned
This parameter is deprecated and scheduled for removal. Use the StorageFormat instead. Indicate to the underlyi
ng file system, that the virtual disk backing file should be allocated lazily (using thin provisioning). This p
arameter is only used for file systems that support configuring the provisioning policy on a per file basis, su
ch as VMFS3. This parameter is supported only if the DiskType parameter is set to "flat".

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-StorageFormat
Specify the storage format of the new hard disk. The valid values are Thin and Thick.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-DeviceName
Specify the host-specific device the LUN is being accessed through. If the target LUN is not available on the h
ost then it is empty. For example, this could happen if it has accidentally been masked out. Only supported whe
n DiskType is set to "rawVirtual" or "rawPhysical". The device name is visible in the vSphere Client through th
e new raw hard disk wizard or can be retrieved using PowerCLI views.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Datastore
Specify 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 a
n 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.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? true

-VM
Specify the virtual machines to which you want to add the new disk.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? true

-Server
Specify the vSphere servers on which you want to run the cmdlet. If no value is given to this parameter, the co
mmand runs on the default servers. For more information about default servers, see the description of Connect-V
IServer.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? true

-WhatIf
Indicate that the cmdlet is run only to display the changes that would be made and actually no objects are modi
fied.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

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

Required? false
Position? named
Default value $true
Accept pipeline input? false
Accept wildcard characters? false

-DiskPath
Specify the path to the hard disk.

Required? true
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS



OUTPUTS
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 supported.

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

C:\PS>$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 --------------

C:\PS>$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 virtu
al machine, with the obtained device name.





-------------- Example 3 --------------

C:\PS>New-HardDisk -VM $vm -CapacityKB 1024000 -Persistence IndependentNonPersistent


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





-------------- Example 4 --------------

C:\PS>New-HardDisk -VM $vm -DiskPath "[storage1] OtherVM/OtherVM.vmdk"


Attaches an available disk from a *.vmdk file.





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

C:\PS>$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 descri
bing the rule and creates the new hard disk.






RELATED LINKS
Online version: http://www.vmware.com/support/developer/PowerCLI/PowerCLI501/html/New-HardDisk.html
Copy-HardDisk
Get-HardDisk
Remove-HardDisk
Set-HardDisk