Combine PowerShell script into one line

Copper Contributor

Hi,
i've this powershell command the retrieved process CPU usage

 

 

(Get-Counter '\Process(*)\% Processor Time').Countersamples | where-object{$_.InstanceName -ne "_total" -and $_.InstanceName -ne "idle" -and $_.CookedValue/$env:NUMBER_OF_PROCESSORS -gt 5} |Sort CookedValue -Desc | ft InstanceName,@{Name='CPU %';Expr={[Math]::Round($_.CookedValue / $env:NUMBER_OF_PROCESSORS)}}

 

 

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

 

THX

1 Reply
If I understand you correct, then the simple answer is to create a PSCustomObect and store the result there