Combining WMI cmdlets to export to csv

Hope someone can help. Doesn’t seem like i can output it so that it can be properly exported. This is the best output i seem to be able to do.

$qry1 = Get-wmiobject -class win32_perfformatteddata_perfproc_process | select WorkingSetPeak
$qry2 = Get-WmiObject -class win32_process | select processname,commandline

[pscustomobject]@{
processname=$($qry2.processname)
commandline=$($qry2.commandline)
WorkingSetPeak=$($qry1.WorkingSetPeak)
}

Are you wanting something like the following in your csv?

ProcessName, CommandLine, WorkingSetPeak

“Hello”, “C:\Hello.exe”,“6160384”

If so, I would just use Get-Process because it already has all the properties you want.

Get-Process |
    Select-Object Name, Path, PeakWorkingSet |
        Export-Csv .\yourcsv.csv

 

 

Hi Mike,

It was just an example. I know that the two cmdlets have those properties already. But there are some properties that i would like to take a little from both cmdlets and be able to combine them and export to csv.

Hope this makes sense

If you are combining properties, I assume in your hypothetical that the data is related by a common property like PID or path. If so you can create a computed property like this for example:

Get-Process |
    Select-Object Name, 
                  Path, 
                  @{n="hash"
                  e={(Get-FileHash -Path $_.path).hash}}

 

Here’s another example where I keyed off of the PID and Parent PID.

Get-CimInstance -ClassName win32_process |
    Select-Object -Property ProcessName,
                            @{n="Parent"
                            e={Get-Process | 
                                Where-Object ID -eq $_.ParentProcessID |
                                    Select-Object -expandproperty Name}}