I have an awesome script that gives vital data for running worker processes. What I'm attempting to do is to get these three values into a table so that they can be displayed all pretty-like. I previously used a .net extension to accomplish this but I've add problems with compatibility so I'd like to use strictly Powershell here. Here is my script:
$myprocess = "w3w*"
$filter = "*\process(" + $myprocess + ")*"
$pids = get-counter -listset process | get-counter -maxsamples 1 | select -expandproperty countersamples | where {$_.path -like "*\id process" -and $_.path -like $filter} | select cookedvalue | ForEach {$_.cookedvalue}
$wsp = get-counter -listset process | get-counter -maxsamples 1 | select -expandproperty countersamples | where {$_.path -like "*\working set" -and $_.path -like $filter} | select cookedvalue | ForEach {$_.cookedvalue}
$w3wpn = $pids | foreach {
$filter = "processid='" + $_ + "'"
$wmip = gwmi Win32_Process -filter $filter
if($wmip.CommandLine -match "-ap `"(.+)`"") {
$appName = $matches[1] -replace '([^^"].)".*', '$1'
Write-Output $appName
}}
'WP,IP,Memory',$w3wpn,$pids,$wsp | ConvertFrom-CSV | Format-Table -Auto
and here is the output I'm looking for:
WP Process ID Mem (KB)
-- ---------- --------
MyAppPool 4816 76,435,456
AnotherAppPool 16924 205,369,344
DefaultAppPool 34508 233,574,400