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.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
crankygeek01@gmail.com
Posts: 5
Last visit: Wed May 10, 2023 9:06 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked