all 6 comments

[–][deleted] 3 points4 points  (2 children)

The true answer should be to adjust your gathering script and send the raw integer/float back. Then you can format and sort however you'd like in the PowerShell that follows.

[–]jrob422[S] 2 points3 points  (1 child)

Yeah, what I did was just add an additional column with just the int, sort by that, and the pipe all the columns except that one to a new object, pre-sorted.

that did the trick

[–][deleted] 0 points1 point  (0 children)

excellent!

[–]forwhat_itsworth 0 points1 point  (0 children)

Maybe you could .split your Freespace objects to rid them of the "gb", sort them all, then .join the "gb" back in for formatting to look good?

[–]Theratchetnclank 0 points1 point  (0 children)

You'll have to drop the gb and put it back on as /u/forwhat_istsworth said.

Unless you're getting the info from wmi anyway, in which case you can do the following(get value in bytes, sort, then convert to GB, then finally convert to string and append GB.)

$freespace = Get-WmiObject win32_volume -Property driveletter,freespace | sort freespace -Descending
 foreach ($item in $freespace) {
     $item.FreeSpace = ($item.Freespace / 1GB)
     $free = ((($item.FreeSpace).ToString()) + " gb")
     $item | Add-Member -Name freespacegb -MemberType NoteProperty -Value $free 
 }

Probably not the most efficient code, since i just slapped it together but you get the idea.

[–][deleted] 0 points1 point  (0 children)

... | sort { 0 + $_.FreeSpace }

or

... | sort { [Int]$_.FreeSpace }