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 }





Thanks a lot. It really helped in automating the disk resizing.
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
}
For me is not working 🙁
Worked for me. But needed to restart server for invoke script to work.
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.