Sort function in Powershell not working

Home Forums Scripting PowerShell Sort function in Powershell not working

This topic contains 7 replies, has 4 voices, and was last updated by  weirdo 1 year, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts

  • jason0923
    Participant
    #167073

    I’m trying to export a report in Office 365 of users online Archives. The export works but I want to be able to sort the data to make it easier to read. I’ve used the Sort-Object command vefore but now its not working and I get the data unsorted. Am I missing something simple? This is the command I am using

    Get-Mailbox -Resultsize unlimited -Filter {customattribute1 -eq “staff”} | Get-MailboxStatistics -archive -erroraction silentlycontinue | select DisplayName,TotalItemSize | Sort-object “TotalItemSize (MB)” -Descending | Export-CSV “C:user dataArchive.csv”


    Ossian
    Moderator
    #191712

    Are you using “TotalItemSize” or “TotalItemSize (MB)” ?


    weirdo
    Member
    #390576

    I’ve tried both


    Ossian
    Moderator
    #191713

    Yes, but you have two different ones in the script above – that definitely wont work!


    weirdo
    Member
    #390577

    What do you mean I have Sort-object “TotalItemSize (MB)” -Descending thats the only sort one. The Select part just gives the columns


    JeremyW
    Moderator
    #271504

    This issue is that the TotalItemSize is displayed and sorted as a string. So you’ll have to do some parsing because you can’t access the actual data and only the display of it.

    Get-Mailbox -Resultsize unlimited -Filter {customattribute1 -eq “staff”} | Get-MailboxStatistics -archive -erroraction silentlycontinue | Select DisplayName,@{name=”TotalItemSize (MB)”;expression={[math]::Round((($_.TotalItemSize.Value.ToString()).Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}} | Sort-object “TotalItemSize (MB)” -Descending | Export-CSV “C:user dataArchive.csv”[/CODE]

    More info: [url]https://msdn.microsoft.com/en-us/library/gg576861(v=exchsrvcs.149).aspx[/url][CODE]Get-Mailbox -Resultsize unlimited -Filter {customattribute1 -eq “staff”} | Get-MailboxStatistics -archive -erroraction silentlycontinue | Select DisplayName,@{name=”TotalItemSize (MB)”;expression={[math]::Round((($_.TotalItemSize.Value.ToString()).Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}} | Sort-object “TotalItemSize (MB)” -Descending | Export-CSV “C:user dataArchive.csv”[/CODE]

    More info: https://msdn.microsoft.com/en-us/library/gg576861(v=exchsrvcs.149).aspx


    weirdo
    Member
    #390578

    Thanks that worked perfectly


    JeremyW
    Moderator
    #271507

    Glad to help. 8)

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.