You are here:

WindowsManagement.com > PowerShell > PowerShell 1.0 > Sort-Object
ActiveXperts Network Monitor 2019 proactively manages network servers, devices, databases and more.

Sort-Object - PowerShell 1.0

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.

Sort-Object


Description
Back up your Hyper-V VMs Easy & Fast. 100% built for Hyper-V. Free for 2 VMs, forever.

Usage


Options
-property Object
       A property or properties to use when sorting.

   -inputObject psobject
       The objects to be sorted. (may be piped)

   -culture string
       The cultural/country configuration to use when sorting.

   -caseSensitive
       Sort UPPER and lower case letters separately.

   -unique 
       Return only the unique values.

   -descending 
       Sort in descending order.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Example(s)
List the files in the current directory and sort using the default order (alphabetical by Name):

PS C:\>get-childitem | sort-object

List the files in the current directory and sort by date/time:

PS C:\>get-childitem | sort-object -property LastWriteTime

List the files in the current directory and sort in descending order by the time span between CreationTime and LastWriteTime:

PS C:\>get-childitem *.* | sort-object @{Expression={$_.LastWriteTime-$_.CreationTime}; Ascending=$false} | select-object LastWriteTime, CreationTime