I am looking for a way to use the powercli to increase the size of hard disks from 25gb to 40gb on a large amount of vms. Then the I was wondering if the cli would be able to go onto those machines and use diskpart to increase the size of the drives within windows.
Thanks for any help
Have a look at the Set-Harddisk cmdlet with the HelperVM parameter.
Unfortunately not a lot of OS are supported.
You could eventually launch the diskpart command inside the guest through the Invoke-VMScript cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
We will be using 2008 and 2008 r2, which I believe is supported by this command. Would this command have to be issued for each vm or is there a way to automate it?
That is exactly the strength of PowerCLI, you can script the repetitive tasks.
For example: the Get-VM cmdlet will retrieve all the guests registered on the vSphere server you are connected to.
You can then the pipeline to link several cmdlets together.
For example
Get-VM MySrv* | Get-Harddisk | Set-Harddisk -CapacityKB (40 * 1MB) -HelperVM (Get-VM Helper)
will retrieve all guests whose name starts with MySrv, then it will fetch the harddisk and extend it to 40GB with the help of the HelperVM called Helper.
Note that you do lost more with PowerCLI !
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Would I then be able to use darkpart through the powercli to expand the disks in windows?
The HelperVM does all that for you. No need to run diskpart yourself.
See the post called Resizing a VM's Windows system OS with Set-HardDisk to see how this is done.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Why is it that you have to have both the vm and the helper vm turned off for this process, when if you were not to automate it and use diskpart, the machine would still be up and there would be no downtime?
My understanding of the process; the helperVM connects to the harddisk of the vm and then starts.
That way you can also increase the size of the bootdisk, on the helperVM the disk will not be the bootdisk.
Yes, you can do this with Set-Harddisk and then invoke diskpart, but it will not work for the bootdisk.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
I want to add some clarifications:
GuestDiskExpansion_WindowsGuest.bat - windows family machines
GuestDiskExpansion_winXPProGuest.bat- explicitly for VMs with guestID WinXpPro
Example:
$hdd = Get-VM myVM | Get-Harddisk | ? {$_.Name -like "HardDisk 2"}
Set-HardDisk -HardDisk $hdd -CapacityKb 4*1MB -GuestUser administrator -GuestPassword <password> -Partition D
Note that we've noticed some issues when resizing boot partition of the w7 and w2k8 VM since the OS perform scandisk when a new hdd is attach. This causes Set-HardDisk to wait for some user interaction in the guest OS.
Hope this helps.
Regards,
Yasen
PowerCLI Dev team
Im still unclear as to why this method depends on the machine being down if I can resize the boot partition on 2008 through the disk management utitlity with no downtime.
Could this be because the cmdlet supports more guest OSs then just W2K8 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If we could just take this in steps, what would be the command for just extending the disks on the virtual side. So that i could get that tested then worry about the windows portion of it.
That would be the Set-Harddisk cmdlet with the CapacityKB parameter.
This will increase the hard disk on MyVM to 11GB.
Get-VM MyVM | Get-Harddisk | Set-Harddisk -CapacityKB (11 * 1MB) -Confirm:$false
Note that you can also pass Guest and Host credentials, the cmdlet will then try to increase the disksize also inside the guest OS.
If you don't pass the credentials, the increase will only be done on the virtual level.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am using the following script to increase the size of hard drives on virtual machines. It gets the names from a text document. After testing I noticked that it does all hard drives on each vm. What do I have to change in my script to make it select a particular drive to expand.
$a = Get-Content "C:\Scripts\Test.txt"
foreach ($i in $a)
{Get-VM $i | Get-Harddisk | Set-Harddisk -CapacityKB (40 * 1MB) -Confirm:$false}
You can use a where-clause to filter out specific hard disks.
For example to increase Hard disk 2 on the VMs you could do
$a = Get-Content "C:\Scripts\Test.txt"
foreach ($i in $a)
{Get-VM $i | Get-Harddisk | where{$_.Name -eq "Hard disk 2"} | Set-Harddisk -CapacityKB (40 * 1MB) -Confirm:$false}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello, chuckado-
To only set the size of a particular hard disk for each VM, you can add a Where-Object clause to the pipeline in the Foreach loop, like:
...
{Get-VM $i | Get-Harddisk | Where-Object {$_.Name -eq "Hard disk 2"} | Set-Harddisk -CapacityKB (40 * 1MB) -Confirm:$false}
You could use a .csv file in which you specify on each row the name of a virtual machine, the hard disk which size you want to increase and the new size. Like this:
VM,HardDisk,SizeGB
VM1,Hard disk 2,40
VM2,Hard disk 3,50
Using this .csv file and the next PowerCLI script you can increase only the hard disks you want:
Import-Csv -Path "Test.csv" | ` ForEach-Object { $Row = $_ Get-VM -Name $Row.VM | Get-Harddisk | ` Where-Object {$_.Name -eq $Row.HardDisk} | ` Set-Harddisk -CapacityKB (1MB * $Row.SizeGB) -Confirm:$false }
Regards, Robert