L'objectif de ce script est d'effectuer la vérification du ratio de la RAM sur l'ensemble des Clusters
<#
. AUTEUR : Antoine JOVELIN
. FONCTION : Vérification du ratio de la RAM sur l'ensemble des Clusters
. UTILISATION :
- Lancer le script
#>
cls
# Declaration des fonctions
function vcenter-connect{
$VC = Read-Host -Prompt " Entrer le nom de vCenter "
$cred = Get-Credential
Write-Host;
Write-Host -ForegroundColor cyan "Connexion à vCenter. Merci de patienter..."
Connect-VIServer $VC -Credential $cred
Write-Host;
}
function vcenter-disconnect{
Write-Host;
Write-Host -ForegroundColor cyan "Déconnexion de vCenter..."
Disconnect-viserver -Server $Global:DefaultVIServer -Confirm:$false -Force
Write-Host;
}
# Debut du script
vcenter-connect
Write-Host;
Write-Host -fore cyan "
###############################################################
# Vérification du ratio de la RAM sur l'ensemble des Clusters #
###############################################################"
Write-Host;
$getcluster=Get-Cluster;
ForEach($clustername in $getcluster){
write-host;
write-host "Traitement du Cluster " -NoNewline; write-host $clustername -ForegroundColor Yellow;
$vmhosts=Get-Cluster $clustername|Get-VMHost;
$Output=@();
$Output1=@();
$totalhostram=0;
$totalvram=0;
$totalratio=0;
ForEach ($vmhost in $vmhosts){
$ratio=$null;
$hostvram=0;
$vms = Get-Cluster $clustername | Get-VMHost $vmhost | Get-VM | where {$_.PowerState -eq "PoweredOn"};
ForEach ($vm in $vms){$vram=0;
$vram = $vm.MemoryGB;
$hostvram += $vram
};
$totalvram += $hostvram;
$hostram="{0:N0}" -f ($vmhost.memorytotalGB);
$ratio = "{0:N1}" -f ($hostvram/$hostram);
$hvalue= New-Object psobject;
$hvalue| Add-Member -MemberType Noteproperty "Hostname" -value $vmhost.name;
$hvalue| Add-Member -MemberType Noteproperty "hRAM" -Value $hostram;
$hvalue| Add-Member -MemberType Noteproperty "vRAM" -Value $hostvram;
$hvalue| Add-Member -MemberType Noteproperty "Ratio" -Value $ratio;
$Output+=$hvalue;
$totalhostram += $hostram
};
$totalratio = "{0:N1}" -f ($totalvram/$totalhostram);
$cvalue= New-Object psobject;
$cvalue| Add-Member -MemberType Noteproperty "Hostname" -value "Cluster";
$cvalue| Add-Member -MemberType Noteproperty "hRAM" -Value $totalhostram;
$cvalue| Add-Member -MemberType Noteproperty "vRam" -Value $totalvram;
$cvalue| Add-Member -MemberType Noteproperty "Ratio" -Value $totalratio;
$Output1+=$cvalue;
$Output|ft -autosize;
$Output1|ft –autosize
}
Write-Host;
vcenter-disconnect