Set-HardDisk
This cmdlet modifies the properties of the specified virtual hard disk. You can encrypt the specified virtual hard disk or decrypt the specified virtual hard disk. You can also change the size and the persistence type, and inflate or expand the specified virtual hard disk. Do not use the Inflate parameter at the same time with the Persistence and CapacityGB parameters. If you use a helper virtual machine, all virtual machines associated with the disk and the helper virtual machine should be powered off before expanding the disk. When you resize more than one disk by using a helper virtual machine, the disks are resized one by one causing the helper machine to power on and off for each virtual machine. This might slow the cmdlet performance. For a list of supported operating systems, see the VMware PowerCLI User's Guide.
Syntax
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
DisableEncryption | SwitchParameter | named |
|
Indicates that the cmdlet decrypts the specified hard disk. |
required
|
HardDisk | HardDisk[] | named |
|
Specifies the virtual hard disk you want to configure. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | RunAsync | SwitchParameter | named |
|
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console. |
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
HardDisk | HardDisk[] | named |
|
Specifies the virtual hard disk you want to configure. |
optional | KeyProvider | KeyProvider | named |
|
Specifies the key provider that you want to use for the encryption key while encrypting the specified hard disk. If StoragePolicy is not specified, the default encryption storage policy "VM Encryption Policy" is used. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | RunAsync | SwitchParameter | named |
|
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console. |
optional | StoragePolicy | StoragePolicy | named |
|
Specifies the StoragePolicy that you want to attach to the specified hard disk. If the storage policy is an encryption policy, the hard disk is encrypted. |
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
HardDisk | HardDisk[] | named |
|
Specifies the virtual hard disk you want to configure. |
optional | Inflate | SwitchParameter | named |
|
Indicates that you want to inflate the hard disk. |
optional | ProgressAction | ActionPreference | named |
|
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
HardDisk | HardDisk[] | named |
|
Specifies the virtual hard disk you want to configure. |
optional | CapacityKB | Int64 | 1 |
|
This parameter is obsolete. Use CapacityGB instead. Specifies the updated capacity of the virtual disk in kilobytes (KB). If you are connected to a vCenter Server 2.0 or ESX 3.0 server, the size of the disk cannot be changed and the CapacityKB parameter is discarded. If you are connected to a vCenter Server 2.5 or ESX 3.5 server, the size of the disk can only be increased and the CapacityKB parameter is discarded if its value is less than the current disk size. |
optional | Persistence | String | 2 |
|
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 rawVirtual or flat. The NonPersistent and Undoable values are deprecated and scheduled for removal. These values do not work with snapshots and are not supported on ESXi 3.5 and later. |
optional | Datastore | Datastore | 3 |
|
Specifies the datastore to which you want to move the specified hard disk. Moving a hard disk attached to a virtual machine to a different datastore is only supported on vCenter Server. |
optional | CapacityGB | Decimal | named |
|
Specifies the updated capacity of the virtual disk in gigabytes (GB). If you are connected to a vCenter Server 2.0 or ESX 3.0, the size of the disk cannot be changed and the CapacityGB parameter is discarded. If you are connected to a vCenter Server 2.5 or ESX 3.5, the size of the disk can only be increased and the CapacityGB parameter is discarded if its value is less than the current disk size. |
optional | Controller | ScsiController | named |
|
Specifies a SCSI controller to which you want to attach the hard disk. |
optional | GuestCredential | PSCredential | named |
|
Specifies the PSCredential object that contains the credentials you want to use for authenticating with the guest operating system. |
optional | GuestPassword | SecureString | named |
|
Specifies the password you want to use for authenticating with the guest operating system. |
optional | GuestUser | String | named |
|
Specifies the username you want to use for authenticating with the guest operating system. |
optional | HelperVM | VirtualMachine | named |
|
Specifies a helper virtual machine you want to use when expanding a Windows virtual machine system disk. LVM (logical volume manager) for Linux is not supported and Linux guest system disks cannot be expanded. When you use a helper virtual machine, all virtual machines associated with the disk and the helper virtual machine must be powered off before expanding the disk. When you resize more than one disks using a helper virtual machine, the disks are resized one by one causing the helper machine to power on and off for each virtual machine, and this might slow down the cmdlet's performance. |
optional | HostCredential | PSCredential | named |
|
Specifies the PSCredential object that contains the credentials you want to use for authenticating with the host. |
optional | HostPassword | SecureString | named |
|
Specifies the password you want to use for authenticating with the host. |
optional | HostUser | String | named |
|
Specifies the user name you want to use for authenticating with the host. |
optional | Partition | String | named |
|
Specifies the partitions you want to resize. On Windows, you can specify which partition you want to resize by using the Partition parameter. If you do not specify a partition, the last partition of the disk is resized. On Linux, you can expand only the last partition. Resizing guest partitions is supported only for Windows OS and for ext3 partitions on RHEL 5. It is achieved by scripts, provided with the VMware PowerCLI installation. You can modify these scripts or add new ones to support operating systems different than Windows and RHEL 5, and more specific disk resizing scenarios. The scripts are located in the "Scripts" folder in the PowerCLI installation directory and their names have the following format: GuestDiskExpansion_<OS_Identifier> <OS_Identifier> is the guest family or the guest ID (as returned by Get-VMGuest). If no partition is specified, the last partition of the hard disk is resized. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | ResizeGuestPartition | SwitchParameter | named |
|
Note: This functionality is deprecated and is not functional on the currently supported guest operating systems. Resizing guest disks works only on Windows XP Service Pack 3 and Red Hat Enterprise Linux 5. Indicates that you want to resize the guest partition of the disk. To use this feature, VMware Tools must run on the virtual machine. On Windows, you can specify which partition you want to resize by using the Partition parameter. If you don't specify a partition, the last partition of the disk is resized. On Linux, you can expand only the last partition. Resizing guest partitions is supported only for Windows OS and for ext3 partitions on RHEL 5. It is achieved by scripts, provided with the VMware PowerCLI installation. You can modify these scripts or add new ones to support operating systems different than Windows and RHEL 5, and more specific disk resizing scenarios. The scripts are located in the "Scripts" folder in the PowerCLI installation directory and their names have the following format: GuestDiskExpansion_<OS_Identifier> <OS_Identifier> is the guest family or the guest ID (as returned by Get-VMGuest). |
optional | Server | VIServer[] | named |
|
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 | StorageFormat | VirtualDiskStorageFormat | named |
|
Specifies the storage format of the relocated hard disk. This parameter is applicable only when moving a virtual machine disk to a different datastore by using the Datastore parameter. This parameter accepts Thin, Thick, and EagerZeroedThick values. |
optional | ToolsWaitSecs | Int32 | named |
|
Specifies the time in seconds to wait for a response from VMware Tools. If a non-positive value is provided, the system waits an infinitely long time. |
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
HardDisk | HardDisk[] | named |
|
Specifies the virtual hard disk you want to configure. |
optional | CapacityKB | Int64 | 1 |
|
This parameter is obsolete. Use CapacityGB instead. Specifies the updated capacity of the virtual disk in kilobytes (KB). If you are connected to a vCenter Server 2.0 or ESX 3.0 server, the size of the disk cannot be changed and the CapacityKB parameter is discarded. If you are connected to a vCenter Server 2.5 or ESX 3.5 server, the size of the disk can only be increased and the CapacityKB parameter is discarded if its value is less than the current disk size. |
optional | Persistence | String | 2 |
|
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 rawVirtual or flat. The NonPersistent and Undoable values are deprecated and scheduled for removal. These values do not work with snapshots and are not supported on ESXi 3.5 and later. |
optional | Datastore | Datastore | 3 |
|
Specifies the datastore to which you want to move the specified hard disk. Moving a hard disk attached to a virtual machine to a different datastore is only supported on vCenter Server. |
optional | CapacityGB | Decimal | named |
|
Specifies the updated capacity of the virtual disk in gigabytes (GB). If you are connected to a vCenter Server 2.0 or ESX 3.0, the size of the disk cannot be changed and the CapacityGB parameter is discarded. If you are connected to a vCenter Server 2.5 or ESX 3.5, the size of the disk can only be increased and the CapacityGB parameter is discarded if its value is less than the current disk size. |
optional | Controller | ScsiController | named |
|
Specifies a SCSI controller to which you want to attach the hard disk. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | Server | VIServer[] | named |
|
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 | StorageFormat | VirtualDiskStorageFormat | named |
|
Specifies the storage format of the relocated hard disk. This parameter is applicable only when moving a virtual machine disk to a different datastore by using the Datastore parameter. This parameter accepts Thin, Thick, and EagerZeroedThick values. |
Parameters
Required | Parameter Name | Type | Position | Features | Description |
---|---|---|---|---|---|
required
|
HardDisk | HardDisk[] | named |
|
Specifies the virtual hard disk you want to configure. |
optional | ProgressAction | ActionPreference | named |
|
|
optional | ZeroOut | SwitchParameter | named |
|
Specifies that you want to fill the hard disk with zeros. This parameter is supported only if you are directly connected to an ESX/ESXi host. |
Output
VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.HardDiskExamples
Example 1
Get-HardDisk -VM $vm | Set-HardDisk -Persistence "IndependentNonPersistent"
Changes the persistence of a hard disk to IndependentNonPersistent.
Example 2
Set-HardDisk -HardDisk $harddisk -CapacityGB $extendedCapacity -GuestCredential $guestCred
Extends a hard disk with the specified capacity. The command also extends the disk on the guest operating system.
Example 3
Set-HardDisk -HardDisk $harddisk -Datastore $datastore
Moves the hard disk to the specified datastore.
Example 4
$policy = Get-SpbmStoragePolicy | select -first 1 Set-HardDisk -HardDisk $harddisk -StoragePolicy $policy
Attaches the StoragePolicy $policy to the specified hard disk. If the $policy is an encryption policy, the specified hard disk is encrypted. If the $policy is a non-encryption policy, the specified hard disk is decrypted (if it is encrypted before this cmdlet) and attached with the new policy.
Example 5
Set-HardDisk -HardDisk $harddisk -DisableEncryption
Decrypts the specified hard disk.
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.