Friday, August 31, 2012

HyperV Expand Disk powershell

Expand Disk

# Assumes that there is only 1 'disk' and 1 object
$TVM = get-vm | where-object { $_.vmelementname -like "*wallace1"}
#Shut down server so that we can expand disk
shutdown-vm  $TVM -wait
#locate the disk
$TDisk=$TVM | get-vmdisk | where-object{ $_.drivename -eq "Hard Drive"}
#Expand the disk
Expand-VHD $TDisk.diskpath 25gb -wait
#Power server back online 
$TVM | Start-vm -wait

next step is to set it to loop thru each server, then power down, expand the C: drive only to 45GB.


$TVM = get-vm
$TVD = $TVM | get-vmdisk | where-object{ $_.drivename -eq "Hard Drive" -AND $_.Controllername -eq "IDE Controller 0" -AND $_.DriveLUN -eq 0}
$TVM |Foreach-object {Shutdown-vm -wait}
$TVD |Foreach-object {Expand-VHD $_.diskpath 45GB -wait}


Expand Disk on Windows 2012 (of course the commands change)

get-vm | get-vmharddiskdrive | foreach-object {resize-vhd $_.path -sizebyte 80GB}

till next time.

1 comment:

Unknown said...

Virtual Machine : windows 2008
Host : windows 2008 R2
disk : C:\clusterstorage\hdrive.vhd

unable to increase the vhd.