Windows如何使用PowerShell查看内存使用情况

查看windows可用内存

param( [string]$computer = "." )
 
$free = ( Get-WMIObject Win32_OperatingSystem -ComputerName $computer ).FreePhysicalMemory * 1KB
$phys = ( Get-WMIObject Win32_OperatingSystem -ComputerName $computer ).TotalVisibleMemorySize * 1KB

Write-Host
Write-Host "Physical memory".PadRight( 16, " " ) -NoNewline
Write-Host "Bytes".PadLeft( 14, " " ) -NoNewline
Write-Host "KB".PadLeft( 11, " " ) -NoNewline
Write-Host "MB".PadLeft( 8, " " )
Write-Host ( "=" * 49 )
Write-Host "Available".PadRight( 16, " " ) -NoNewline
Write-Host ([string]$free).PadLeft( 14, " " ) -NoNewline
Write-Host ([string][int]($free / 1KB)).PadLeft( 11, " " ) -NoNewline
Write-Host ([string][int]($free / 1MB)).PadLeft( 8, " " )
Write-Host "Total".PadRight( 16, " " ) -NoNewline
Write-Host ([string]$phys).PadLeft( 14, " " ) -NoNewline
Write-Host ([string][int]($phys / 1KB)).PadLeft( 11, " " ) -NoNewline
Write-Host ([string][int]($phys / 1MB)).PadLeft( 8, " " )
Write-Host
日期:2020-04-11 23:04:32 来源:oir作者:oir