![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Sorting a hashtable I wrote this command to show the size of all sub-folders in a folder: dir | ? { $_.PsIsContainer } | % { $t=0;dir -rec $_.Name | % {$t += $_.Length }; @{$_.Name=$t}} This outputs: Name Value ---- ----- Avaya 1887047 C# 294 PowerShell 8643 Regular Expressions 161 Sql 3914 Windows 1964032 Now, I'd like to sort them by size (or the "Value" property of the Hashtable). I append "sort value" to the end of my command: dir | ? { $_.PsIsContainer } | % { $t=0;dir -rec $_.Name | % {$t += $_.Length }; @{$_.Name=$t}} | sort value But I get: Name Value ---- ----- Regular Expressions 161 Sql 3914 Windows 1964032 Avaya 1887047 C# 294 PowerShell 8643 How do I get this to sort?! |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Sorting a hashtable There should be other ways to accomplish sorting Hashtable data by "value"s, but the easiest way is to access the "Values" property of pipeline object of type Hashtable. dir | ? {$_.PsIsContainer} | % { $t=0; ls -r $_.Name | % {$t += $_.Length }; @{ $_.Name=$t } } | sort {$_.Values} In the last section of the pipeline, "sort-object"'s input object takes in script block argument and sort by the "Values" property of the hashtable object. |
My System Specs![]() |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| comparing hashtable values | Cookiecutter | PowerShell | 4 | 05-20-2008 10:36 AM |
| How to sort a hashtable? | Tibor Soos | PowerShell | 3 | 01-31-2008 09:26 AM |
| Creating a hashtable in the pipeline? | gurbao | PowerShell | 2 | 05-18-2007 08:03 AM |
| Filter a hashtable? | gurbao | PowerShell | 1 | 05-18-2007 01:18 AM |
| sorting on hashtable values | Neil Chambers | PowerShell | 3 | 04-08-2007 03:49 AM |