Forum Discussion
SimonSays1
Dec 05, 2021Copper Contributor
Filter by nested properties of type timespan
Hi folks, I am new to powershell and I wanted to understand the concepts behind it and play a bit with filtering by objects resp. by properties. For example I wanted to filter the output of get-proc...
- Dec 06, 2021
Hello SimonSays1,
You are correct TotalProcessorTime is TimeSpan and you can use .seconds property to view the seconds.
The problem that you are facing is related to pipeline processing. In your Where condition you need to use $_ to reference the object that being passed through the pipeline.
get-process | where {$_.TotalProcessorTime.Seconds -gt 1}Reference: about_Pipelines
Hope that helps.
AndySvints
Dec 06, 2021Steel Contributor
Hello SimonSays1,
You are correct TotalProcessorTime is TimeSpan and you can use .seconds property to view the seconds.
The problem that you are facing is related to pipeline processing. In your Where condition you need to use $_ to reference the object that being passed through the pipeline.
get-process | where {$_.TotalProcessorTime.Seconds -gt 1}Reference: about_Pipelines
Hope that helps.
- SimonSays1Dec 10, 2021Copper ContributorHi AndySvints,
thank you very much! I thought I would not need necessarily the $_ to reference the object. And thank for the reference!