PowerShell, VMWare, Windows

Expand VM Hard-Disk with PowerShell

If you have a need to increase the disk of a VM running on VMware infrastructure and then expand it at guest level you might have noticed that the “ResizeGuestPartition”  has been deprecated – thus leaving us to resort on Invoke-Command like so:

#Script increasing VM disk size to 100GB & expands OS disk to maximum available size
$vm = IISDEVVM01
Get-HardDisk -vm $vm | Where {$_.Name -eq "Hard disk 1"} | Set-HardDisk -CapacityGB 100 -Confirm:$false

Invoke-Command -ComputerName $vm -ScriptBlock {
$size = Get-PartitionSupportedSize -DriveLetter C 
Resize-Partition -DriveLetter C -Size $size.SizeMax



5 Comments to “Expand VM Hard-Disk with PowerShell”

  1. Yue Yao

    Very helpfull!
    But if you optimize VM with disabling service defragsvc, you have change its starttype to ‘manual’:
    in scriptblock:
    if ( (get-service defragsvc).StartType -eq “disabled”) {
    get-service defragsvc | set-service -starttype manual

  2. Kevin

    This worked great! I had been forced to use diskpart and invoke-command, but with this, i can use invoke-vmscript (powercli) and it doesn’t block it with UAC!

    Tested on VMWare 6.5 and Server 2019 Datacenter.


Leave a Comment

Your email address will not be published. Required fields are marked *