# Need help with formatting output from 2 commands

**URL:** <https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639>\
**Category:** PowerShell Help\
**Created:** [December 3, 2016, 3:56pm UTC](https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639 "2016-12-03T15:56:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob-jaudon](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@rob-jaudon](https://forums.powershell.org/u/rob-jaudon)\
**Post date:** [December 3, 2016, 3:56pm UTC](https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639/1 "2016-12-03T15:56:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![random-commandline](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@random-commandline](https://forums.powershell.org/u/random-commandline)\
**Post date:** [December 3, 2016, 6:33pm UTC](https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639/2 "2016-12-03T18:33:53Z")

</div>

```
$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
```

---

<div class="post-metadata">

**Author:** ![rob-jaudon](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@rob-jaudon](https://forums.powershell.org/u/rob-jaudon)\
**Post date:** [December 3, 2016, 9:04pm UTC](https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639/3 "2016-12-03T21:04:18Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![dweda](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@dweda](https://forums.powershell.org/u/dweda)\
**Post date:** [December 4, 2016, 7:03am UTC](https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639/4 "2016-12-04T07:03:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/need-help-with-formatting-output-from-2-commands/7639/5 "2024-05-16T20:39:48Z")

</div>


