VMware Cloud Community
BaluVirigineni
Enthusiast
Enthusiast

Need a powercli script to increase Harddisk1 of VMs in a folder by 20GB, can someone give a script..

I have around 30VMs under a Folder, for which I need to increase Harddisk1 by 20GB, can someone provide me a script to accomplish same.

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership

I assume, since you mention Harddisk1, that this VMDK holds the system partition ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
BaluVirigineni
Enthusiast
Enthusiast

Yes LucD, they windows 2k8 Servers..I am trying to increase system partition by 20GB.

Reply
0 Kudos
LucD
Leadership
Leadership

If the VMs have a supported OS, you can do something like this

$folderName = "MyFolder"
$helperName = "MyHelperVM"
$extraGB = 20

$helperVM = Get-VM -Name $helperName
if($helperVM.PowerState -ne "PoweredOff"){
 
"The HelperVM needs to be powered off !"
 
return
}

Get-Folder -Name $folderName | Get-VM | %{
 
if($_.PowerState -eq "PoweredOff"){
   
$hd = Get-HardDisk -VM $_ | where {$_.Name -eq "Hard disk 1"} |
   
Set-HardDisk -HardDisk $hd -CapacityGB ($hd.CapacityGB + $extraGB) -HelperVM $helperVM -ResizeGuestPartition
  }
 
else{
   
"VM $($vm.Name) is not powerd off"
  }
}

It's possible that you need to provide credentials for the guest OS on the Set-Harddisk cmdlet


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

BaluVirigineni
Enthusiast
Enthusiast

Thanks its working fine..

Reply
0 Kudos