Here is what i am trying to achieve.
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.
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
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