Welcome › Forums › General PowerShell Q&A › Combining WMI cmdlets to export to csv
- This topic has 4 replies, 2 voices, and was last updated 1 month, 2 weeks ago by
Participant.
-
AuthorPosts
-
-
November 30, 2020 at 1:59 pm #275394
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)
} -
November 30, 2020 at 2:39 pm #275409
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.
PowerShell123Get-Process |Select-Object Name, Path, PeakWorkingSet |Export-Csv .\yourcsv.csv -
November 30, 2020 at 2:42 pm #275415
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
-
November 30, 2020 at 2:46 pm #275418
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:
PowerShell12345Get-Process |Select-Object Name,Path,@{n="hash"e={(Get-FileHash -Path $_.path).hash}} -
November 30, 2020 at 2:58 pm #275421
Here’s another example where I keyed off of the PID and Parent PID.
PowerShell123456Get-CimInstance -ClassName win32_process |Select-Object -Property ProcessName,@{n="Parent"e={Get-Process |Where-Object ID -eq $_.ParentProcessID |Select-Object -expandproperty Name}}
-
-
AuthorPosts
- You must be logged in to reply to this topic.