PowerCLI

 View Only
  • 1.  Grow a VMs disk via PowerCLI

    Posted Jul 16, 2013 05:49 PM

    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!



  • 2.  RE: Grow a VMs disk via PowerCLI
    Best Answer

    Posted Jul 16, 2013 06:16 PM

    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 !



  • 3.  RE: Grow a VMs disk via PowerCLI

    Posted Jul 16, 2013 06:17 PM

    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



  • 4.  RE: Grow a VMs disk via PowerCLI

    Posted Jul 16, 2013 06:20 PM

    Fyi, you don't have to do that in 2 steps afaik, you can add the ResizeGuestPartion switch on the first line



  • 5.  RE: Grow a VMs disk via PowerCLI

    Posted Jul 16, 2013 06:29 PM

    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!



  • 6.  RE: Grow a VMs disk via PowerCLI

    Broadcom Employee
    Posted Jul 19, 2013 02:14 PM

    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!



  • 7.  RE: Grow a VMs disk via PowerCLI

    Posted Feb 13, 2014 03:53 PM

    Thanks for this. I also had to add a rescan after selecting the volume, worked great though.



  • 8.  RE: Grow a VMs disk via PowerCLI

    Posted Sep 21, 2016 02:42 PM

    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