Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » Sort-Object

Sort-Object - Powershell 1.0 CmdLet

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 objects by property value


-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.

       Sort UPPER and lower case letters separately.

       Return only the unique values.

       Sort in descending order.

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

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