Powershell Tutorial
Introduction to Powershell Managing History of Powershell Commands Cmdlet, Alias, Function and Module in Powershell PSDrive Profile in Windows Powershell Variable Management in Powershell Passing values to parameters from file Creating files and directories Basic File System commands Finding the patterns in files Unique command Replacing patterns in files Comparing objects Sorting objects Other object commands Getting members of an Object Managing processes Managing Jobs IO redirection Piping System Commands Network commands Service Commands WMI(Windows Management Instrumentation) CIM (Common Information Model) Formatting output exporting output XML processing Powershell Module Management Remote computer managementSorting objects in windows powershell
We can sort the objects based on specific property. For example – “Get-Process” command shows the output where the objects are sorted by process name. But if you want to sort by other property say “handles”, you can use below syntax.
Get-Process | Sort-Object handles
Sorting based on specific column
You can also sort the files based on any column. Below example shows that we are sorting the files by first column. To sort by second column, just replace “0” by “1” and so on.
> Get-Content ./cities.txt | Sort-Object { $_.split()[0] } -Descending
Below example shows that we are sorting the files by first column but numerically. Note that we have casted the first column value to integer. To sort by second column, just replace “0” by “1” and so on.
> Get-Content ./cities.txt | Sort-Object { [int]$_.split()[0] } -Descending
Web development and Automation testing
solutions delivered!!