You are currently viewing PowerShell Sort-Object Cmdlet

PowerShell Sort-Object Cmdlet

PowerShell Sort-Object Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Group-Object cmdlet in PowerShell.

https://cloudaffaire.com/powershell-group-object-cmdlet/

In this blog post, we will discuss the Sort-Object cmdlet in PowerShell. You can use the Sort-Object cmdlet to sort the output or objects in ascending or descending order based on object property values supplied to Sort-Object cmdlet. If no object property mentioned, Sort-Object sorts the result based on 1st input object it gets. Sort-Object cmdlet can sort on a single object property or multiple object properties. By default, the Sort-Object cmdlet sorts objects in ascending order. You can also use the Unique parameter to eliminate duplicates from the output of Sort-Object.

Sort-Object Cmdlet Syntax:

Sort-Object Cmdlet Argument List:

  • Bottom: Specifies the number of objects to get from the end of a sorted object array.
  • CaseSensitive: Indicates that the sort is case-sensitive. By default, sorts are not case-sensitive.
  • Culture: Specifies the cultural configuration to use for sorts.
  • Descending: Indicates that Sort-Object sorts the objects in descending order. The default is ascending order.
  • InputObject: To sort objects, send them down the pipeline to Sort-Object.
  • Property: Specifies the property names that Sort-Object uses to sort the objects.
  • Stable: The sorted objects are delivered in the order they were received when the sort criteria are equal.
  • Top: Specifies the number of objects to get from the start of a sorted object array.
  • Unique: Indicates that Sort-Object eliminates duplicates and returns only the unique members of the collection.

PowerShell Sort-Object Cmdlet:

Sort Objects In Ascending Order Based On Single Property In PowerShell:

Sort Objects In Descending Order Based On Single Property In PowerShell:

Sort Objects Based On Multiple Properties In PowerShell:

Remove Duplicates From Sorted Objects In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss the Where-Object cmdlet in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply