Check Memory Usage

This blog is created as part of my PowerShell learning and getting into the blogging world, so you may see repetitive content. Please bear with me. Here I am posting a simple script that can be used to get RAM memory details from remote windows computers. Please let me know your suggestions on improving the scripts.


Get memory details of a remote server

Get the Available physical memory, FreePhysicalMemory,
and Percentage of Memory Usage remotely.

.PARAMETER ComputerName
Accepts a list of computer names or IP addresses

Get-MemoryUsage -ComputerName computer1
Get-MemoryUsage -ComputerName computer1,computer2



function Get-MemoryUsage{
# A computer name or list of computer names
[string[]]$ComputerName = 'localhost'
$result = @()
foreach ($computer in $ComputerName){
$memory = Get-WmiObject -class win32_operatingsystem -ComputerName $computer | `
Select-Object @{n='ComputerName';e={$_.PSComputerName}},
@{n='TotalMemory GB';e={"{0:N2}" -f [int]($_.TotalVisibleMemorySize / 1MB)}},
@{n='FreePhysicalMemory GB';e={"{0:N2}" -f ($_.FreePhysicalMemory / 1MB)}},
@{n='% MemoryUsage'; e={"{0:N2}" -f ((($_.TotalVisibleMemorySize - `
$_.FreePhysicalMemory)/$_.TotalVisibleMemorySize)*100)}} #| Format-List
$result += $memory


Post a Comment

Popular posts from this blog

Check SQL Server Database Status

PowerShell and Azure Resource Graph

Static Code Analysis: Some Tools