Need help with formatting output from 2 commands

All,

I am needing help with formatting output from 2 different oneliners into an easy readable output.

Below I have 2 cmd I run to monitor proceses on one or more servers.

Here are the commands I run…

get-process -computername av3320 taskmgr|select name,@{l="WorkingSet(MB)}"; e={$_.WorkingSet64 / 1mb}},machinename |sort-object -property Name |ft -AutoSize
get-wmiobject Win32_PerfFormattedData_PerfProc_Process -computername av3320 -Filter "Name='taskmgr' or name='Notepad'"| select PSComputerName,name, PercentProcessorTime,threadcount,Handlecount| ft -Au

I have them both in a ps1 script and the output is as follows…


Name WorkingSet(MB)} MachineName


notepad 13.5 av3320
notepad 45.859375 av3320
notepad 13.5625 av3320
Taskmgr 42.52734375 av3320

PSComputerName name PercentProcessorTime threadcount Handlecount


AV3320 notepad 0 2 176
AV3320 Taskmgr 23 16 504


I would like to have the format of the output as shown below but I don’t know how to make it all come together nicely.

Output I would like to have…

Name WorkingSet(MB)} MachineName PercentProcessorTime threadcount HandleCount


notepad 13.5 av3320 0 2 176
notepad 45.859375 av3320 0 2 152
notepad 13.5625 av3320 0 2 184
Taskmgr 42.52734375 av3320 0 17 505

$procs = Get-Process -Name taskmgr,notepad | Select-Object name,
@{l="WorkingSet(MB)}";e={$_.WorkingSet64 / 1mb}},machinename

$perfs = Get-WmiObject win32_PerfFormattedData_PerfProc_Process -Filter "
Name='taskmgr' OR Name='notepad'" | Select-Object PSComputerName,
name, PercentProcessorTime,threadcount,Handlecount

$output = foreach ($proc in $procs){
    foreach ($perf in $perfs){
        [PSCustomObject]@{
        Name = $proc.Name
        WorkingSet = $proc.'WorkingSet(MB)}'
        MachineName = $proc.MachineName
        PercentProcessorTime = $perf.percentprocessortime
        threadcount = $perf.threadcount
        Handlecount =  $perf.handlecount
}
}
} 

$output | Format-Table -AutoSize

Hello and thank you for your response. I appreciate your help.

This works. However, it duplicates the output …see below. In the below output only 1 instance on Notepad and Taskmgr are running. Can you tell me why?

                                                                                  
Name     WorkingSet MachineName PercentProcessorTime threadcount Handlecount      
----     ---------- ----------- -------------------- ----------- -----------      
notepad 35.39453125 .                              0           4         496      
notepad 35.39453125 .                              0          18         527      
Taskmgr 40.54296875 .                              0           4         496      
Taskmgr 40.54296875 .                              0          18         527

Hi Rob,

If you just need the output it I think you can achieve this with the following lines.

$computername = 'av3320'
$CIMInstances = Get-CimInstance Win32_PerfFormattedData_PerfProc_Process -ComputerName $computername -Filter "Name='taskmgr' or Name= 'notepad' or name like'notepad#%'" 


Foreach($CIMInstance in $CIMInstances)
{
get-process -computername $CIMInstance.PSComputerName -Id $CIMInstance.idprocess|
select-object name,
@{Name="WorkingSet(MB)}"; e={$_.WorkingSet64 / 1MB}},
machinename,
@{Name="PercentProcessorTime"; e={$CIMInstance.PercentProcessorTime}},
@{Name="threadcount"; e={$CIMInstance.threadcount}},
@{Name="Handlecount"; e={$CIMInstance.Handlecount}},id|ft -AutoSize
}

I added ID to see if they are different and query on multiple instances of notepad.
Also I worked with CIM because this is faster and the new way of doing this.
If you want to use the output later in your script to work with I would go for above solution creating a custom object.
If you just need this output I think you are fine for now.