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'
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
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
This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here