vSphere PowerCLI Reference

Set-HardDisk

Synopsis

Changes the properties of the specified virtual hard disk.

Syntax

Set-HardDisk [-HardDisk] <HardDisk[]> [[-CapacityKB] <Int64>] [-CapacityGB <Decimal>] [[-Persistence] <String>] [[-Datastore] <Datastore>] [-StorageFormat <VirtualDiskStorageFormat>] [-Controller <ScsiController>] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-HardDisk [-HardDisk] <HardDisk[]> [[-CapacityKB] <Int64>] [-CapacityGB <Decimal>] [[-Persistence] <String>] [[-Datastore] <Datastore>] [-StorageFormat <VirtualDiskStorageFormat>] [-Controller <ScsiController>] [-Server <VIServer[]>] [-HostCredential <PSCredential>] [-HostUser <String>] [-HostPassword <SecureString>] [-GuestCredential <PSCredential>] [-GuestUser <String>] [-GuestPassword <SecureString>] [-ToolsWaitSecs <Int32>] [-HelperVM <VirtualMachine>] [-Partition <String>] [-ResizeGuestPartition] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-HardDisk [-HardDisk] <HardDisk[]> [-Inflate] [-WhatIf] [-Confirm] [<CommonParameters>]
Set-HardDisk [-HardDisk] <HardDisk[]> [-ZeroOut] [-WhatIf] [-Confirm] [<CommonParameters>]

Related Commands

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

Detailed Description

Changes the properties of the specified virtual hard disk. You can 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 a helper virtual machine is used, 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 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 the cmdlet performance. The guest disk resizing functionality supports only Windows XP 32 SP3, Windows Server 2003 32bit SP2, Windows Server 2003 64bit SP2, Windows 7 64 bit, Windows Server 2008 R2 64bit and Redhat Enterprise 5 guest operating systems. Please consider the Set-HardDisk feature to be experimental as it might be changed or removed in a future release.

To run this cmdlet to resize guest disk partitions against vCenter Server/ESX/ESXi versions earlier than 5.0, you need to meet the following requirements:
*You must run the cmdlet on the 32-bit version of Windows PowerShell.
*You must have access to the ESX that hosts the virtual machine over TCP port 902.
*For vCenter Server/ESX/ESXi versions earlier than 4.1, you need VirtualMachine.Interact.ConsoleInteract privilege. For vCenter Server/ESX/ESXi 4.1 and later, you need VirtualMachine.Interact.GuestControl privilege.

To run this cmdlet to resize guest disk partitions against vCenter Server/ESXi 5.0 and later, you need VirtualMachine.GuestOperations.Execute and VirtualMachine.GuestOperations.Modify privileges.

Parameters

NameTypeDescriptionRequired?Pipeline InputDefault Value
HardDiskHardDisk[]Specify the virtual hard disk you want to configure.truetrue (ByValue)
CapacityKBInt64This parameter is obsolete. Use CapacityGB instead.
Specify 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.
falsefalse
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 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
DatastoreDatastoreSpecify 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.falsefalse
CapacityGBDecimalSpecify the updated capacity of the virtual disk in gigabytes (GB). 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 CapacityGB 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 CapacityGB parameter is discarded if its value is less than the current disk size.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 hard disk.falsefalse
GuestCredentialPSCredentialSpecify the PSCredential object that contains the credentials you want to use in authentication with the guest operating system.falsefalse
GuestPasswordSecureStringSpecify a password you want to use in authentication with the guest operating system.falsefalse
GuestUserStringSpecify a username you want to use in authentication with the guest operating system.falsefalse
HelperVMVirtualMachineSpecify 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 a helper virtual machine is used, 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 performance.
falsefalse
HostCredentialPSCredentialSpecify the PSCredential object that contains the credentials you want to use in authentication with the host.falsefalse
HostPasswordSecureStringSpecify a password you want to use in authentication with the host.falsefalse
HostUserStringSpecify a username you want to use in authentication with the host.falsefalse
InflateSwitchParameterIndicate that you want to inflate the hard disk.falsefalse
PartitionStringSpecify the partitions you want to resize. 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, only the last partition can be expanded.

Resizing guest partitions is supported only for Windows OS and for ext3 partitions on RHEL 5. It is achieved by scripts, provided with the vSphere 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.
falsefalse
ResizeGuestPartitionSwitchParameterIndicate that you want to resize the guest partition of the disk. To use this feature, VMware Tools must be running 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, only the last partition can be expanded.

Resizing guest partitions is supported only for Windows OS and for ext3 partitions on RHEL 5. It is achieved by scripts, provided with the vSphere 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).
falsefalse
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
StorageFormatVirtualDiskStorageFormatSpecify the storage format of the relocated hard disk. This parameter is applicable only when moving a virtual machine disk to a different datastore, using the Datastore parameter. This parameter accepts Thin, Thick, and EagerZeroedThick values.falsefalse
ToolsWaitSecsInt32Specify the time in seconds to wait for a response from the VMware Tools. If a non-positive value is provided, the system waits infinitely long time.falsefalse$null
WhatIfSwitchParameterIndicate that the cmdlet is run only to display the changes that would be made and actually no objects are modified.falsefalse
ZeroOutSwitchParameterSpecify that you want to fill the hard disk with zeros. This parameter is supported only if you are directly connected to an ESX host. The ZeroOut functionality is experimental.falsefalse

Return Type

HardDisk

Notes

Set-HardDisk cannot inflate a hard disk that has already been inflated. Non-persistent and undoable disks are not supported. Migrating a hard disk attached to a virtual machine to a different datastor e is supported only on vCenter Server.

Examples

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

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

Set-HardDisk -HardDisk $harddisk -Datastore $datastore

Moves the hard disk to the specified datastore.


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