Hello,
I'm looking to grow some volumes on some servers via PowerCLI. I've gotten the below code to successfully extend the volume inside the guest OS once I increase it's configured size via the GUI.
Get-HardDisk "VM Name" | where {$_.Name -eq "hard disk 2"} | Set-HardDisk -CapacityGB 20 -ResizeGuestPartition -Confirm:$false
My question is:
Is there a way to increase the provisioned size of a disk via PowerCLI that I could run prior to the code above that extends the volume inside the guest OS?
Thanks in advance for any help!
Like every good answer, I will have to start with "it depends" :smileygrin:
If this is not the vdisk that holds the system partition, you can just use the Set-Harddisk cmdlet with the CapacityGB parameter. See Example 2.
If it is the system partition vdisk, you will have to use the HelperVM parameter on the Set-Harddisk cmdlet.
Note that the VM and the HelperVM both need to be powered off !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Like every good answer, I will have to start with "it depends" :smileygrin:
If this is not the vdisk that holds the system partition, you can just use the Set-Harddisk cmdlet with the CapacityGB parameter. See Example 2.
If it is the system partition vdisk, you will have to use the HelperVM parameter on the Set-Harddisk cmdlet.
Note that the VM and the HelperVM both need to be powered off !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
figures after looking through the forums and googling for serveral hours 10 minutes after posting the question I find it. for anyone looking to do this below is what worked for me.
expands the provisioned size of the vmdk
Get-HardDisk -vm "My VM" | where {$_.Name -eq "Hard Disk 2"} | Set-HardDisk -CapacityGB 25 -Confirm:$false
extends the volume inside the guest OS
Get-HardDisk -vm "My VM" | where {$_.Name -eq "hard disk 2"} | Set-HardDisk -CapacityGB 25 -ResizeGuestPartition -Confirm:$false
Fyi, you don't have to do that in 2 steps afaik, you can add the ResizeGuestPartion switch on the first line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yup, your right LucD I looked at that cmdlet I don't know how may times and misunderstood the Capacity parameter.... Thanks for the reply!
I just tried it all in one line and it does indeed work. Thanks again!
I recently had a need to resize the system partition on a couple of Windows 2008R2 VMs. Since the -ResizeGuestPartition switch does not work in this scenario, I used Invoke-VMScript to run diskpart inside the OS instead.
Invoke-VMScript -vm $guestName -ScriptText "echo select vol c > c:\diskpart.txt && echo extend >> c:\diskpart.txt && diskpart.exe /s c:\diskpart.txt" -GuestUser $guestUser -GuestPassword $guestPass -ScriptType BAT
Hope this helps!
Thanks for this. I also had to add a rescan after selecting the volume, worked great though.
Worked Great for me .. thanks guys!
#List VM Disk Space
Get-HardDisk -VM VMNAME | fl CapacityGB,Name,StorageFormat
#Expand Disk Drive:
Get-HardDisk -VM VMNAME | where {$_.Name -eq "Hard disk 1"} | Set-HardDisk -CapacityGB 34 -ResizeGuestPartition -Confirm:$false
#List VM Disk Space
Get-HardDisk -VM VMNAME | fl CapacityGB,Name,StorageFormat