lunedì 9 marzo 2020

VMs Memory information

Problem
I need a fast way to check the Memory usage of the last 30 days to understand if there are more RAMs than needed in the VMs.

Solution
Below a very simple PowerCLI script that will return information about Minimum, Maximum and Avarage Memory of the last 30 days.
First of all, after you have opened a powershell terminal (doesn't mind if Windows/Linux/MacOS), you need to connect to the vCenter Server, providing a proper User and Password:

Connect-VIServer -Server “IP/hostname/FQDN”
Once connected you can execute the following command:

$Report = @()
foreach ($VM in Get-VM) {
  $vmstat=@{}
 $vmstat.VMname = $vm.Name     
 $statmem = Get-Stat -Entity ($vm)-start (get-date).AddDays(-30) -Finish (get-date).AddDays(-1) -MaxSamples 10000 -stat mem.usage.average
 $mem = $statmem | Measure-Object -Property value -Average -Maximum -Minimum
 $vmstat.MemMax = [math]::round($mem.Maximum,2)
 $vmstat.MemAvg = [math]::round($mem.Average,2)
 $vmstat.MemMin = [math]::round($mem.Minimum,2)
 $temp = New-Object -TypeName PSObject -Property $vmstat
    $Report += $temp
} 
$Report | Select VMname, MemMax, MemAvg, MemMin | Format-Table -AutoSize 



That's it.

Nessun commento:

Posta un commento