Page 1 of 1

Using DataGridView unable to sort

Posted: Fri Aug 03, 2018 12:13 pm
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
	

Re: Using DataGridView unable to sort

Posted: Fri Aug 03, 2018 12:25 pm
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