Sunday, 30 July 2017

GET-Memory Useage function

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
}



No comments:

Post a Comment

Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress

#Powershell function to get theremote server IP details,Subnetmask,Gateway,DHCP Enabled status,DNS Servers,Wins and Macaddress # use...