Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Validating Memory and Datastore space

$
0
0

Hi,

 

I am trying to validate host memory and datastore space before I continue with script, I would like to exit the script, even anyone of the validation fail

 

How can I achieve this from below script,

 

please help

 

$vmhowime = 300

$intNewVMDiskSize = 1000

 

$vmh = Get-Cluster MyClus | Get-VMHost | Sort-Object -Property {$_.MemoryTotalGB - $_.MemoryUsageGB} -Descending:$true | Select-Object -First 1

if (($vmh.MemoryTotalGB - $vmh.MemoryUsageGB + 20) -gt $vmhowime) {

    $($vmh.Name)

}

else {

    "oh, no -- not enough freememory on any of the host '$($vmh.Name)' to provision new VM, hence exiting the script"

    disconnect-viserver -server * -force -confirm:$false

}

 

$oDatastoreWithMostFree = Get-Datastore | Sort-Object -Property FreespaceGB -Descending:$true | Select-Object -First 1

if (($oDatastoreWithMostFree.FreespaceGB + 20) -gt $intNewVMDiskSize) {$($oDatastoreWithMostFree.Name)} else {"oh, no -- not enough freespace on datastore '$($oDatastoreWithMostFree.Name)' to provision new VM"}

 

Get-folder | get-vm


Viewing all articles
Browse latest Browse all 179681

Trending Articles