VMware Cloud Community
tdubb123
Expert
Expert

set-harddisk +10GB

any idea how I can add +10GB to existing "hard disk 1"  without having to know the current capacity?

0 Kudos
7 Replies
LucD
Leadership
Leadership

Try like this

Get-VM -Name MyVM | Get-HardDisk -Name 'Hard disk 1' |

ForEach-Object -Process {

   Set-HardDisk -HardDisk $_ -CapacityGB (10 + $_.CapacityGB) -Confirm:$false

}


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

0 Kudos
tdubb123
Expert
Expert

Hi Luc

when i tried this it only made a 1GB to 10GB instead of 11GB

this is my command

Get-VM -Name test | Get-HardDisk -Name 'Hard disk 2' | Set-HardDisk -CapacityGB (10 + $_.CApacitygb)

0 Kudos
LucD
Leadership
Leadership

That will not work, you can only reference the pipeline object ($_) in a script block.

See my previous answer.


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

0 Kudos
tdubb123
Expert
Expert

thank Luc. That works.

however when i add resizeguestpartition to it. seems to have frozen up

Screen Shot 2019-05-23 at 3.20.11 PM.png

0 Kudos
LucD
Leadership
Leadership

Did you see the warning on the help entry for the Set-Harddisk cmdlet?

"Note: This functionality is deprecated and is not functional on the currently supported guest operating systems. Resizing guest disks works only on Windows XP Service Pack 3 and Red Hat Enterprise Linux 5. "

That might be causing the hang.


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

0 Kudos
tdubb123
Expert
Expert

I got this working only on the first VM on the servers.txt list when expanding the  E drive. but failedon the second.

any idea whats going on?

Screen Shot 2019-05-24 at 7.05.24 AM.png

If I go back and manually run

invoke-command -computername server2 -scriptblock $scriptblock -credential $creds

it works fine

0 Kudos
LucD
Leadership
Leadership

You get that error when the used space on the partition is higher than the value you pass on the Size parameter.


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

0 Kudos