and i’ve this powershell command that retrieved process IO usage
Get-WmiObject Win32_PerfFormattedData_PerfProc_Process | where-object{ $_.Name -ne "_Total" -and $_.Name -ne "Idle" -and $_.IODataBytesPersec -gt 1048576 } | Sort-Object IODataBytesPersec -Descending | select @{Name='Process Name'; E={$_.Name}},@{Name="Total IO Per sec in MB";Expression={[math]::round($_.IODataBytesPersec/1048576,2)}},@{Name="Read IO Per sec in MB";Expression={[math]::round($_.IOReadBytesPersec/1048576,2)}},@{Name="Write IO Per sec in MB";Expression={[math]::round($_.IOWriteBytesPersec/1048576,2)}} | Format-list
how can i combine those 2 powershell scripts into one line powershell script that take the process with the CPU usage and also collect the IOPS usage for it?
i know that Win32_PerfFormattedData_PerfProc_Proces have process CPU usage but it’s not accurate like the CookedValue in Get-Counter ‘\Process(*)% Processor Time’).Countersamples
before we proceed, please go back, edit your post and fix the formatting of the code. Without that the forum software tries to “parse” your code and removes some characters like underscores.
To format code as code use the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks in advance
BTW: It’s considered good style to use line breaks after each pipe symbol. It’ll make your code much easier to read and to understand.
I’d consider adding line breaks after each of your calculated properties as well when you have more than one.
And it’s considered good style as well not to use aliasses.
Now I’d like to make sure I understood the question correctly.
If you want to run more than one command in sequence you can simply concatenate them with a semicilon or save them in a script and run the script instead of the individual commands.
If you want to combine the results of two commands in one output object they need to have one common property to be combined with.
i can’t add a line breaks because i run this PowerShell from within SQL SERVER and the script must be in one line.
regard my question - what i want and don’t know how to do it is to take the process name and the CPU usage from the first powershell and pass the process name to the second powershell and get the IOPS for the same process in one line\sentence.
If you need it in your case for a technical reason it’s fine. But that does not mean you have to do it here as well. Here you’re dealing with human beings willing to help you.