Using DataGridView unable to sort

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
crankygeek01@gmail.com
Posts: 5
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Tue May 15, 2018 8:56 am

Using DataGridView unable to sort

Post by crankygeek01@gmail.com »

When I run the following command in Exchange powershell it get the expected output..

When put into a DataGridView I get incorrect output, it seems like it doesn't sort descending

Code:

Code: Select all

$MBsizes = Get-MailboxStatistics -Database Mailboxes |
	where  { $_.Displayname -notlike "SystemMail*" -And $_.Displayname -notlike "HealthMailbox*" -And $_.DisplayName -notlike "In-Place*" } |
	sort TotalItemSize -Descending | select -first 5| Select DisplayName, TotalItemSize, StorageLimitStatus
	Update-DataGridView -DataGridView $datagridviewResults -Item $MBsizes -AutoSizeColumns DisplayedCells
	

jvierra
Posts: 14447
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Using DataGridView unable to sort

Post by jvierra »

"TotalItemSize" is not a number it is an object. It is a string and strings don't sort correctly.

Run at a prompt and inspect the object.

Get-MailboxStatistics -Database Mailboxes | select -expand TotalItemSize

Locked