- PowerShell Tutorial
- PowerShell - Home
- PowerShell - Overview
- PowerShell - Environment Setup
- PowerShell - Cmdlets
- PowerShell - Files and Folders
- PowerShell - Dates and Timers
- PowerShell - Files I/O
- PowerShell - Advanced Cmdlets
- PowerShell - Scripting
- PowerShell - Special Variables
- PowerShell - Operators
- PowerShell - Looping
- PowerShell - Conditions
- PowerShell - Array
- PowerShell - Hashtables
- PowerShell - Regex
- PowerShell - Backtick
- PowerShell - Brackets
- PowerShell - Alias
- PowerShell Useful Resources
- PowerShell - Quick Guide
- PowerShell - Useful Resources
- PowerShell - Discussion
Powershell - Sort-Object Cmdlet
Cmdlet
Sort-Object cmdlet is used to sort object by its properties.
In these example, we're see the Sort-Object cmdlet in action.
Example 1
In this example, we'll sort objects using Process properties.
Get-Process | Sort-Object -Property WS | Select-Object -Last 5
Output
You can see the process with high memory usages.
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 314 44 134528 108492 760 28.38 1536 powershell_ise 579 25 116552 124832 205 21.68 256 svchost 1249 59 77132 130152 433 41.90 4392 chrome 329 42 104748 133704 1935 59.22 4368 chrome 604 67 163376 149552 277 0.45 3152 mysqld
Example 2
In this example, we'll sort an array.
"d","e","c","a","b","f" | Sort-Object
Output
You can see the following output.
a b c d e f
powershell_advanced_cmdlets.htm
Advertisements
To Continue Learning Please Login
Login with Google