Skip to content

Commit a816099

Browse files
Improve Get-Process Ex 4 Priority grouping
The Priority table view for Diagnostics.Process groups on the PriorityClass property. Format-Table expects input to already be sorted, but the original example used unsorted data, rendering it fairly unhelpful. This adds a call to Sort-Object and sorts on PriorityClass before calling Format-Table. This ensures all processes are correctly grouped by the Priority view. A script block is used in lieu of the property name directly, as the latter surfaces getter exceptions as a non-terminating error. This will occur with, e.g., PPL processes in Windows (even when elevated). Reference to PS home directory .ps1xml files is also removed from the v7.x docs. Format definitions were moved directly into source code in v6+. As a Format-* cmdlet is used, the term "display" is used to emphasize output is not intended for further processing.
1 parent 0ba1498 commit a816099

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

reference/5.1/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,22 @@ objects to the `Where-Object` cmdlet, which selects only the object with a value
113113
`Get-Process | Get-Member`. By default, the values of all amount properties are in bytes, even
114114
though the default display lists them in kilobytes and megabytes.
115115

116-
### Example 4: List processes on the computer in groups based on priority
116+
### Example 4: Display processes on the computer in groups based on priority
117117

118118
```powershell
119-
$A = Get-Process
120-
$A | Get-Process | Format-Table -View Priority
119+
$processes = Get-Process
120+
$processes | Sort-Object { $_.PriorityClass } | Format-Table -View Priority
121121
```
122122

123-
These commands list the processes on the computer in groups based on their priority class. The first
124-
command gets all the processes on the computer and then stores them in the `$A` variable.
123+
These commands display processes on the computer in groups based on their
124+
[priority class](/dotnet/api/system.diagnostics.processpriorityclass). The first command gets all
125+
processes on the computer and stores them in the `$processes` variable.
125126

126-
The second command pipes the **Process** object stored in the `$A` variable to the `Get-Process`
127-
cmdlet, then to the `Format-Table` cmdlet, which formats the processes by using the **Priority**
128-
view.
127+
The second command pipes the **Process** objects stored in the `$processes` variable to the
128+
`Sort-Object` cmdlet, then to the `Format-Table` cmdlet, which formats the processes using the
129+
**Priority** view.
129130

130-
The **Priority** view, and other views, are defined in the PS1XML format files in the PowerShell
131+
The **Priority** view, and other views, are defined in the `.ps1xml` format files in the PowerShell
131132
home directory (`$PSHOME`).
132133

133134
### Example 5: Add a property to the standard Get-Process output display

reference/7.4/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ objects to the `Where-Object` cmdlet, which selects only the object with a value
110110
`Get-Process | Get-Member`. By default, the values of all amount properties are in bytes, even
111111
though the default display lists them in kilobytes and megabytes.
112112

113-
### Example 4: List processes on the computer in groups based on priority
113+
### Example 4: Display processes on the computer in groups based on priority
114114

115115
```powershell
116-
$A = Get-Process
117-
$A | Get-Process | Format-Table -View Priority
116+
$processes = Get-Process
117+
$processes | Sort-Object { $_.PriorityClass } | Format-Table -View Priority
118118
```
119119

120-
These commands list the processes on the computer in groups based on their priority class. The first
121-
command gets all the processes on the computer and then stores them in the `$A` variable.
120+
These commands display processes on the computer in groups based on their
121+
[priority class](/dotnet/api/system.diagnostics.processpriorityclass). The first command gets all
122+
processes on the computer and stores them in the `$processes` variable.
122123

123-
The second command pipes the **Process** object stored in the `$A` variable to the `Get-Process`
124-
cmdlet, then to the `Format-Table` cmdlet, which formats the processes by using the **Priority**
125-
view.
126-
127-
The **Priority** view, and other views, are defined in the PS1XML format files in the PowerShell
128-
home directory (`$PSHOME`).
124+
The second command pipes the **Process** objects stored in the `$processes` variable to the
125+
`Sort-Object` cmdlet, then to the `Format-Table` cmdlet, which formats the processes using the
126+
**Priority** view.
129127

130128
### Example 5: Add a property to the standard Get-Process output display
131129

reference/7.5/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ objects to the `Where-Object` cmdlet, which selects only the object with a value
110110
`Get-Process | Get-Member`. By default, the values of all amount properties are in bytes, even
111111
though the default display lists them in kilobytes and megabytes.
112112

113-
### Example 4: List processes on the computer in groups based on priority
113+
### Example 4: Display processes on the computer in groups based on priority
114114

115115
```powershell
116-
$A = Get-Process
117-
$A | Get-Process | Format-Table -View Priority
116+
$processes = Get-Process
117+
$processes | Sort-Object { $_.PriorityClass } | Format-Table -View Priority
118118
```
119119

120-
These commands list the processes on the computer in groups based on their priority class. The first
121-
command gets all the processes on the computer and then stores them in the `$A` variable.
120+
These commands display processes on the computer in groups based on their
121+
[priority class](/dotnet/api/system.diagnostics.processpriorityclass). The first command gets all
122+
processes on the computer and stores them in the `$processes` variable.
122123

123-
The second command pipes the **Process** object stored in the `$A` variable to the `Get-Process`
124-
cmdlet, then to the `Format-Table` cmdlet, which formats the processes by using the **Priority**
125-
view.
126-
127-
The **Priority** view, and other views, are defined in the PS1XML format files in the PowerShell
128-
home directory (`$PSHOME`).
124+
The second command pipes the **Process** objects stored in the `$processes` variable to the
125+
`Sort-Object` cmdlet, then to the `Format-Table` cmdlet, which formats the processes using the
126+
**Priority** view.
129127

130128
### Example 5: Add a property to the standard Get-Process output display
131129

reference/7.6/Microsoft.PowerShell.Management/Get-Process.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,20 @@ objects to the `Where-Object` cmdlet, which selects only the object with a value
110110
`Get-Process | Get-Member`. By default, the values of all amount properties are in bytes, even
111111
though the default display lists them in kilobytes and megabytes.
112112

113-
### Example 4: List processes on the computer in groups based on priority
113+
### Example 4: Display processes on the computer in groups based on priority
114114

115115
```powershell
116-
$A = Get-Process
117-
$A | Get-Process | Format-Table -View Priority
116+
$processes = Get-Process
117+
$processes | Sort-Object { $_.PriorityClass } | Format-Table -View Priority
118118
```
119119

120-
These commands list the processes on the computer in groups based on their priority class. The first
121-
command gets all the processes on the computer and then stores them in the `$A` variable.
120+
These commands display processes on the computer in groups based on their
121+
[priority class](/dotnet/api/system.diagnostics.processpriorityclass). The first command gets all
122+
processes on the computer and stores them in the `$processes` variable.
122123

123-
The second command pipes the **Process** object stored in the `$A` variable to the `Get-Process`
124-
cmdlet, then to the `Format-Table` cmdlet, which formats the processes by using the **Priority**
125-
view.
126-
127-
The **Priority** view, and other views, are defined in the PS1XML format files in the PowerShell
128-
home directory (`$PSHOME`).
124+
The second command pipes the **Process** objects stored in the `$processes` variable to the
125+
`Sort-Object` cmdlet, then to the `Format-Table` cmdlet, which formats the processes using the
126+
**Priority** view.
129127

130128
### Example 5: Add a property to the standard Get-Process output display
131129

0 commit comments

Comments
 (0)