Site icon Franky's Web

PowerShell: Read out the memory consumption of a process remotely (WMI)

WMI queries can be used to find out how much memory a specific process requires on a computer. The following script searches for computers with a specific name in the Active Directory and then reads out the working memory of the computer and the process:

$Procname = „outlook“
$Namefilter = „CLT“
$dnssuffix = „.frankysweb.local“

#——————————————————————
$computers = Get-ADComputer -Filter * | where {$_.name -match „$Namefilter“} | select name
$anzname = „$procname“+“inMB“

$results =@()
foreach ($computer in $computers)
{
$pc = $computer.name
$fqdn = „$pc“ + „$dnssuffix“
$av = test-connection $fqdn -count 1 -erroraction silentlycontinue
if ($av)
{
$ramkb = Get-WmiObject Win32_ComputerSystem -computer $fqdn
$ramkb = $ramkb.TotalPhysicalMemory
$ramgb = $ramkb / 1024 / 1024 / 1024
$ramgb = [decimal]::round($ramgb)

$proclist = get-wmiobject Win32_PerfRawData_PerfProc_Process -computer $fqdn | where {$_.name -match „$procname“}
if ($proclist)
{
$procram = $proclist.WorkingSetPrivate
$procrammb = $procram / 1024 / 1024
$procrammb = [decimal]::round($procrammb)
}
else
{
$procrammb=“0″
}

$results += new-object PSObject -property @{Computer=“$pc“;RAMinGB=“$ramgb“;$anzname=“$procrammb“;FQDN=“$fqdn“}
}
}
$results

Exit mobile version