Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Using PowerCLI to Increase VMDK (Virtual disk) in VMware Virtual Machine

Below oneliner commands I recently used to configure multiple VMware Virtual Machines Hard disk, Task was to grow/extend VMDK virtual disk on more than hundreds of the virtual machine. Below is the main techniques and gist of the article and scripts. These one-liner commands also include the commands to get the disk related inventory so I can gather in the excel file, If I need bulk operations. Here I have first command which shows information about Name of the hard disk drive, CapacityGB, FileName, In the list I want to increase the capacity of hard disk 2. 

Get-VM vm01 | Get-Harddisk | Select Name, CapacityGB, FileName

Once I know which hard disk drive I want to increase, There should be enough space on the datastore if you are going to extend VMDK. You can run Get-Datastore and get the information. and running Move-VM can be used to Storage VMotion vm or its disks to another datastore. Here I have enough disk space and I can easily extend the drive on same datastore. To know the the first one datastore with most free disk space.

Get-Cluster Cluster01 | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select -First 1

Next command is I am listing the Hard Disk from VM which need to be increased.

Get-VM vm01 | Get-HardDisk -Name 'Hard disk 2'

vmware vsphere virtual machine vm extend increase virtual disk hard disk drive vmdk Get-VM Get-Harddisk, get-cluster, get-Datastore .png

Once I verify everything what i need to do and everything is good and I can easily grow the virtual disk, Below command will expand the drive.

Get-VM vm01 | Get-HardDisk -Name 'Hard disk 2' | Set-HardDisk -CapacityGB 8 -Confirm:$false

Although it shows the results but again same result can be verified using cmdlet.

Get-VM vm01 | Get-HardDisk

vmware vsphere esxi virtual machine vm extend increase virtual disk hard disk drive vmdk Get-VM Get-Harddisk, get-cluster, get-Datastore Set-Harddisk datastore.png

This is additional but not exactly related to above task, still below commands can be used with few modifications, if you want to increase drive size below command can help and choose the appropriate drive. This first command will resize the disk size to given size in GB, (Before running you can verify what is the minimum and maximum size value you can use Get-PartitionSupportedSize -DriveLetter C), It can be automated using Invoke-VMScript  or Invoke-Command remotely. 

Resize-Partition -Size 40GB  -DriveLetter C

To use all maximum disk size use as below.
 $size = Get-PartitionSupportedSize -DriveLetter C
 Resize-Partition -DriveLetter C -Size $size.SizeMax

Extend disksize Powershell Resize-partition size driveletter Get-PartitionSupportedSzie maxsize.png

Useful Articles
POWERCLI: VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE
POWERCLI VMWARE: CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER AND ADD VMFS DATASTORE
POWERCLI: VIRTUAL MACHINE STORAGE MIGRATE/SVMOTION AND DATASTORE PORT BINDING MULTIPATHING

Go Back

Comment

Blog Search

Page Views

11240788

Follow me on Blogarama