Powershell script/function to expand system/boot disk on Windows XP/2003 VMs
In Windows 7 and Server 2008 virtual machines and above, expanding the boot/system disk is a simple matter of expanding it in the hypervisor, then expanding it in the guest OS in the Computer Management/Disk Management GUI. In Windows XP/Server 2003 guest VMs, expanding the boot/dystem disk is not available via native Windows tools.
This script leverages Server 2012 R2 hypervisor capabilities to expand boot/system disk on a guest VM running Windows XP/2003 OS. The script leaves a log file behind listing steps taken. The script can be downloaded from the Microsoft Script Center Repository.
To use it: Download the attached file, unblock it, adjust PS execution policy as needed, run the script to load the function in memory, then use this line to get detailed help and examples as shown below:
Note: The script will shutdown the VM during this process.
For example, if you down the VM, and expand the disk in Hyper-V Manager GUI:
In the VM, you cannot expand the boot/system partition with native Windows 2003/XP tools:
You can do that with this script. On the Hyper-V host where the VM is running, run:
Expand-C -VMName MyVM1 -Size 17GB -BackupPath "d:\save"
The script will
- Backup the VHDX file before expanding it if the ‘BackupPath’ is used
- Convert the file from VHD to VHDX format if it was a VHD file. In this case you’ll need to delete the old .vhd file manually.
- Down the VM (gracefully)
- Expand the VHDX file
- Expand the partition
- Re-attach the C: drive disk file to the VM
- Start the VM
- Leave a log file listing the steps taken