PowerCli – Vérifier la sur allocation mémoire sur les ESXs

Connect-VIServer 10.179.100.1

$excel = New-Object -ComObject Excel.Application
$excel.visible = $True
$excel = $excel.Workbooks.Add()
### Initialisation du tableau Excel ###

$Sheet = $Excel.Worksheets.Item(1)
$Sheet.Cells.Item(1,1) = “Nom du Cluster”
$Sheet.Cells.Item(1,2) = “Nom de l’ESX”
$Sheet.Cells.Item(1,3) = “Mémoire Total de l’ESX / Mo”
$Sheet.Cells.Item(1,4) = “Mémoire Total allouée aux VMs / Mo”

$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 15
$WorkBook.Font.Bold = $True
$introw =2

$PowerState = “PoweredOn”
$ESXs = Get-Cluster “MDP-DM-LAB” | Get-VMHost

foreach ($esx in $ESXs){
$mem = Get-VMHost $esx.name | Select     Name,ClusterName,MemoryTotalMB,@{N=”MemoryAllocatedMB”;E={
$_ | Get-VM | where {$_.PowerState -eq $PowerState} | %{($_.MemoryMB / 1KB) -as     [int]} |
Measure-Object -Sum | Select -ExpandProperty Sum}}
#Remplissage du tableau
$Sheet.Cells.Item($intRow, 1) = $mem.ClusterName
$Sheet.Cells.Item($intRow, 2) = $mem.Name
$Sheet.Cells.Item($intRow, 3) = $mem.MemoryTotalMB
$Sheet.Cells.Item($intRow, 4) = $mem.MemoryAllocatedMB
$intRow++
}

 

Source