-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path00_FilteringLeft.ps1
More file actions
27 lines (20 loc) · 1.06 KB
/
00_FilteringLeft.ps1
File metadata and controls
27 lines (20 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Filtering Left
# ----------------------------------------------------------------------------------------------------
# In the pipeline you should always try to filter the results down to what you're looking for as early as possible.
# Use parameters on the first command - filtering left
# early filtering: use parameters to specify what you want to reterieve:
# good example:
Get-Service -Name w32time
# bad example (has a huge performance impact if there are many objects to retrieve):
Get-Service | Where-Object Name -eq w32time
# to show all stopped services - early filtering is not possible because there is no parameter for the Status
# but you can select the Property Status where it equals 'Stopped':
get-service | where Status -eq 'Stopped'
# doesn't return any result because property CanPauseAndContinue wasn't selected
Get-Service |
Select-Object -Property DisplayName, Status |
Where-Object CanPauseAndContinue
# reversing the order and you'll get the result you want:
Get-Service |
Where-Object CanPauseAndContinue |
Select-Object -Property DisplayName, Status