Created a function to check the memory usage on multiple servers
Function Get-MemoryUsage ($ComputerName=$ENV:ComputerName) {
[cmdletbinding()]
$os = Get-Ciminstance Win32_OperatingSystem -ComputerName $ComputerName
$totalvisibleMemmorysize=$os.TotalvisibleMemmorysize
$pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2)
$ser=$os.CSName
if ($pctFree -ge 45) {
$Status = "OK"
}
elseif ($pctFree -ge 15 ) {
$Status = "Warning"
}
else {
$Status = "Critical"
}
$os | Select @{Name = "Servername";Expression = {$ser}},
@{Name = "TotalGB";Expression = {[int]($_.TotalVisibleMemorySize/1mb)}},
@{Name = "FreeGB";Expression = {[math]::Round($_.FreePhysicalMemory/1mb,2)}},
@{Name = "PctFree%"; Expression = {$pctFree}},@{Name = "Status";Expression = {$Status}} | Format-Table -AutoSize
}
Function Get-MemoryUsage ($ComputerName=$ENV:ComputerName) {
[cmdletbinding()]
$os = Get-Ciminstance Win32_OperatingSystem -ComputerName $ComputerName
$totalvisibleMemmorysize=$os.TotalvisibleMemmorysize
$pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2)
$ser=$os.CSName
if ($pctFree -ge 45) {
$Status = "OK"
}
elseif ($pctFree -ge 15 ) {
$Status = "Warning"
}
else {
$Status = "Critical"
}
$os | Select @{Name = "Servername";Expression = {$ser}},
@{Name = "TotalGB";Expression = {[int]($_.TotalVisibleMemorySize/1mb)}},
@{Name = "FreeGB";Expression = {[math]::Round($_.FreePhysicalMemory/1mb,2)}},
@{Name = "PctFree%"; Expression = {$pctFree}},@{Name = "Status";Expression = {$Status}} | Format-Table -AutoSize
}
No comments:
Post a Comment