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.
User avatar
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 »

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

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

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