Filtering the output from commands may be performed using Where-Object. For example, we might filter processes that started after 5 p.m. today:
Get-Process | Where-Object StartTime -gt (Get-Date 17:00:00)
The syntax shown in help for Where-Object does not quite match the syntax used here. The help text is as follows:
Where-Object [-Property] <String> [[-Value] <Object>] -GT ...
In the preceding example, we see the following:
- StartTime is the argument for the Property parameter (first argument by position)
- The comparison is greater than, as signified by the gt switch parameter
- The date (using the Get-Date command) is the argument for the Value parameter (second argument by position)
Based on that, the example might be written as follows:
Get-Process | Where-Object -Property StartTime -Value (Get-Date 17:00:00) -gt
However, it is far easier to read StartTime is greater than <some date>, so most examples tend to follow that pattern.
Where-Object will also accept filters using the FilterScript parameter.