VMware Cloud Community
gajuambi
Enthusiast
Enthusiast
Jump to solution

Extend existing disk conditionally and add if no disk

Here is what i am trying to achieve.

  1. increase the disk space of a particular disk (C & D drive) if they are less than a particular company standard value
  2. detect whether there is a 2nd disk or not and if not then add a 3rd disk

optionally:

a)extend the increased disk from inside the guest OS

b)initialize, format the newly added disk from inside the guest OS

currently this is what i came up with

#if the harddisk 1 is less than 60 increase the hard disk size to 60 and then extend it from inside the guest OS or else skip this action

Get-HardDisk -vm TestVM | where {$_.Name -eq "hard disk 1"} | if ((Measure-Object -Property CapacityGB -Sum) -lt 60) {

Set-HardDisk -CapacityGB 60 -ResizeGuestPartition -Confirm:$false

}

else

{

Write-Host "No action is needed" -foregroundcolor Red

}

Now I do not know how to add a 2nd disk of 80GB after checking whether it has a 2nd disk or not.

My motto behind this is, it should check whether there is a 2nd disk or not and if there is then skip adding the disk and if there is no 2nd disk (hard disk 2) then add an 80GB hard disk.

---------------------- Gajendra D Ambi [pardon my chat lingo]
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something along these lines

$hd = Get-HardDisk -vm TestVM

if($hd.Count -eq 1){

    New-HardDisk -CapacityGB 60 -VM TestVM

}

else{

    Write-Host "2nd HD present - No action is needed" -foregroundcolor Red

}

if($hd[0].CapacityGB -lt 60){

    $hd[0] | Set-HardDisk -CapacityGB 60 -ResizeGuestPartition -Confirm:$false

}

else{

    Write-Host "HD1 is 60GB or more - No action is needed" -foregroundcolor Red

}


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

View solution in original post

0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

You could do something along these lines

$hd = Get-HardDisk -vm TestVM

if($hd.Count -eq 1){

    New-HardDisk -CapacityGB 60 -VM TestVM

}

else{

    Write-Host "2nd HD present - No action is needed" -foregroundcolor Red

}

if($hd[0].CapacityGB -lt 60){

    $hd[0] | Set-HardDisk -CapacityGB 60 -ResizeGuestPartition -Confirm:$false

}

else{

    Write-Host "HD1 is 60GB or more - No action is needed" -foregroundcolor Red

}


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

0 Kudos