Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PowerShell script for sorting data

$
0
0

Hello All,

I'm trying to modify the output of a mailbox report that I run on the Exchange server, I use Exchange Shell to execute the ps1 file. I view these reports in Excel and after the report has been produced I have to make amendments to it in Excel, one of the following amendments is sorting the size from largest to smallest in one of the columns. 

Now I'm sure that this can be automated done within the ps1 file, rather than doing it manually. I've done some research and the following command has come up: 

| Sort-Object -descending 

I've very little knowledge on PowerShell so I don't know where to stick this command. I've done the following below which has not worked: 

$userObj = New-Object PSObject
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $mb.DisplayName
$userObj | Add-Member NoteProperty -Name "Last Mailbox Logon" -Value $lastlogon
$userObj | Add-Member NoteProperty -Name "Last Logon By" -Value $stats.LastLoggedOnUserAccount
$userObj | Add-Member NoteProperty -Name "Item Size (Mb)" -Value $stats.TotalItemSize.Value.ToMB() 
$userObj | Add-Member NoteProperty -Name "Deleted Item Size (Mb)" -Value $stats.TotalDeletedItemSize.Value.ToMB()
$userObj | Add-Member NoteProperty -Name "Items" -Value $stats.ItemCount

$userObj | Sort-Object -descending 

Any suggestions?

Thanks in advance. 


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>