Memory Informationen: Unterschied zwischen den Versionen
Aus Wiki-WebPerfect
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) |
||
Zeile 8: | Zeile 8: | ||
− | == Memory | + | == Get Memory Usage == |
<source lang="powershell"> | <source lang="powershell"> | ||
− | Function | + | Function Get-MemoryUsage { |
[cmdletbinding()] | [cmdletbinding()] | ||
Param() | Param() | ||
− | + | ||
$os = Get-Ciminstance Win32_OperatingSystem | $os = Get-Ciminstance Win32_OperatingSystem | ||
$pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2) | $pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2) | ||
− | + | ||
if ($pctFree -ge 45) { | if ($pctFree -ge 45) { | ||
$Status = "OK" | $Status = "OK" | ||
Zeile 26: | Zeile 26: | ||
$Status = "Critical" | $Status = "Critical" | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | $os | Select @{Name = "Status";Expression = {$Status}}, | ||
+ | @{Name = "TotalGB";Expression = {[int]($_.TotalVisibleMemorySize/1mb)}}, | ||
+ | @{Name = "FreeGB";Expression = {[math]::Round($_.FreePhysicalMemory/1mb,2)}}, | ||
+ | @{Name = "%Free"; Expression = {$pctFree}}, | ||
+ | @{Name=’CommittedGB’;Expression={[math]::Round(($_.totalvirtualmemorysize – $_.freevirtualmemory)/1mb,2)}} | ||
} | } | ||
</source> | </source> |
Version vom 25. Februar 2019, 09:15 Uhr
Plain Memory Info
$MemoryInGB = [math]::Round((Get-Ciminstance Win32_OperatingSystem).TotalVisibleMemorySize/1mb,2) $MemoryInMB = $MemoryInGB * 1024 $MemoryInMB
Get Memory Usage
Function Get-MemoryUsage { [cmdletbinding()] Param() $os = Get-Ciminstance Win32_OperatingSystem $pctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2) if ($pctFree -ge 45) { $Status = "OK" } elseif ($pctFree -ge 15 ) { $Status = "Warning" } else { $Status = "Critical" } $os | Select @{Name = "Status";Expression = {$Status}}, @{Name = "TotalGB";Expression = {[int]($_.TotalVisibleMemorySize/1mb)}}, @{Name = "FreeGB";Expression = {[math]::Round($_.FreePhysicalMemory/1mb,2)}}, @{Name = "%Free"; Expression = {$pctFree}}, @{Name=’CommittedGB’;Expression={[math]::Round(($_.totalvirtualmemorysize – $_.freevirtualmemory)/1mb,2)}} }
Quelle: https://www.petri.com/display-memory-usage-powershell