Announcement

Collapse
No announcement yet.

Sort function in Powershell not working

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sort function in Powershell not working

    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 data\Archive.csv”

  • #2
    Are you using "TotalItemSize" or "TotalItemSize (MB)" ?
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      I've tried both

      Comment


      • #4
        Yes, but you have two different ones in the script above - that definitely wont work!
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


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

          Comment


          • #6
            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.

            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 data\Archive.csv”
            More info: https://msdn.microsoft.com/en-us/lib...rvcs.149).aspx
            Regards,
            Jeremy

            Network Consultant/Engineer
            Baltimore - Washington area and beyond
            www.gma-cpa.com

            Comment


            • #7
              Thanks that worked perfectly

              Comment


              • #8
                Glad to help.
                Regards,
                Jeremy

                Network Consultant/Engineer
                Baltimore - Washington area and beyond
                www.gma-cpa.com

                Comment

                Working...
                X