Created
May 31, 2018 19:44
-
-
Save crossan007/2fe4a459936616705ae9e71447293f8d to your computer and use it in GitHub Desktop.
VirtualBox Resize Disk on VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$VMName = "MyCoolVM" | |
$NewDiskSize = 102400 | |
$VBoxManage = 'C:\Program Files\Oracle\VirtualBox\VBoxManage.exe' | |
# Gather data from VBoxManage | |
$VBOXDrive = & $VBoxManage showvminfo $VMName | Select-String ".vmdk" | |
$RegEx = 'SATA \((\d),\s?(\d)\):\s?(.*?)\s\(UUID:(.*?)\)' | |
$M = [System.Text.RegularExpressions.Regex]::Matches($VBOXDrive,$RegEx) | |
$VMDK = $M.Groups[3].Value | |
$fi = [System.IO.FileInfo]::new($VMDK) | |
$newFile = [System.IO.Path]::Combine($fi.DirectoryName,"$($fi.basename).vdi") | |
#Clone the VHD | |
& $VBoxManage clonehd $VMDK $NewFile --format vdi | |
# Resize the clone | |
& $VBoxManage modifyhd $NewFile --resize $NewDiskSize | |
#Find the storage controller | |
$VBOXController = & $VBoxManage showvminfo $VMName | Select-String "Storage Controller Name" | |
$RegEx = 'Storage Controller Name \(0\):\s*(.*?)$' | |
$M = [System.Text.RegularExpressions.Regex]::Matches($VBOXController,$RegEx) | |
$VBOXControllerName = $M.Groups[1].Value | |
#Attach new | |
& $VBoxManage storageattach $VMName --storagectl $VBOXControllerName --port 0 --device 0 --type hdd --medium $NewFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment