Sorting Stuff

You can use Sort-Object to sort simple variable types. Have a look at the following:

'Tom', 'Chris', 'Judy', 'Alan' | Sort-Object

Input can come from a different command. If you’d like to get seven random lottery numbers, you should try this:

1..49 | Get-Random -Count 7 | Sort-Object

You'll find that when you feed complex objects into Sort-Object, you should specify the object property you want to sort on (or else Sort-Object will pick one by itself):

Get-ChildItem $env:windir | Sort-Object Length

Here are some more examples:

Get-HotFix | Sort-Object InstalledOn
Get-ComputerRestorePoint | Sort-Object Description

Twitter This Tip! ReTweet this Tip!


Posted Apr 23 2010, 08:00 AM by ps1

Comments

Twitter Trackbacks for Sorting Stuff in #PowerShell [powershell.com] on Topsy.com wrote Twitter Trackbacks for Sorting Stuff in #PowerShell [powershell.com] on Topsy.com
on 04-23-2010 10:52 AM

Pingback from  Twitter Trackbacks for                 Sorting Stuff in #PowerShell         [powershell.com]        on Topsy.com

Gameintary – Frogger | Frogger Download wrote Gameintary – Frogger | Frogger Download
on 04-24-2010 12:38 AM

Pingback from  Gameintary – Frogger | Frogger Download

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.