Posted in
Windows Powershell,
Windows Server |
2 Comments | 2,171 views | 13/02/2014 10:51
You can get memory usage of Hyper-V clusters with following script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| $Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
[int]$TotalFreeMemory = 0;
[int]$TotalMemory = 0;
[int]$NodeCount = 0;
$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
[int]$FreeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0)
[int]$TotalFreeMemory = [int]$TotalFreeMemory + [int]$FreeMemory
[int]$NodeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0)
[int]$TotalMemory = [int]$TotalMemory + [int]$NodeMemory
[int]$NodeCount = [int]$NodeCount + 1
}
[int]$TotalAvailableMemory = [int]$TotalFreeMemory - [int]$NodeMemory
Write-Host "Cluster: $Cluster"
Write-Host "Total Memory: $TotalMemory"
Write-Host "Total Free Memory: $TotalFreeMemory"
Write-Host "Total Available Memory: $TotalAvailableMemory"
Write-Host "Node Count: $NodeCount"
Write-Host " "
$Value = $Cluster + ";" + $TotalMemory + ";" + $TotalFreeMemory + ";" + $TotalAvailableMemory + ";" + $NodeCount + ";" + $NodeMemory
Add-Content -Value $Value -Path Memory.txt
} |
$Clusters = Get-Content Clusters.txt
foreach ($Cluster in $Clusters)
{
[int]$TotalFreeMemory = 0;
[int]$TotalMemory = 0;
[int]$NodeCount = 0;
$ClusterNodes = Get-Cluster $Cluster | Get-ClusterNode
foreach ($ClusterNode in $ClusterNodes)
{
[int]$FreeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).FreePhysicalMemory / 1MB), 0)
[int]$TotalFreeMemory = [int]$TotalFreeMemory + [int]$FreeMemory
[int]$NodeMemory = [math]::round(((Get-WmiObject -ComputerName $ClusterNode -Class Win32_OperatingSystem).TotalVisibleMemorySize / 1MB), 0)
[int]$TotalMemory = [int]$TotalMemory + [int]$NodeMemory
[int]$NodeCount = [int]$NodeCount + 1
}
[int]$TotalAvailableMemory = [int]$TotalFreeMemory - [int]$NodeMemory
Write-Host "Cluster: $Cluster"
Write-Host "Total Memory: $TotalMemory"
Write-Host "Total Free Memory: $TotalFreeMemory"
Write-Host "Total Available Memory: $TotalAvailableMemory"
Write-Host "Node Count: $NodeCount"
Write-Host " "
$Value = $Cluster + ";" + $TotalMemory + ";" + $TotalFreeMemory + ";" + $TotalAvailableMemory + ";" + $NodeCount + ";" + $NodeMemory
Add-Content -Value $Value -Path Memory.txt
}
You will see detailed memory usage information of your Hyper-V clusters.