Formatting Output Dilemma

Welcome Forums General PowerShell Q&A Formatting Output Dilemma

Viewing 1 reply thread
  • Author
    • #178305
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Would appreciate some help.  Trying to get a list of Exchange mailboxes and each mailbox's total size.  I have been able to get the Total Size to output, but am unable to output the name of the mailbox along with the size.

      Does anyone have suggestions?  Ideally, I would generate a text file, and each line would contain the name of the mailbox and it's total size, separated by a comma.

      The code I've come up with so far is as follows:

      Get-Content c:\temp\litigationhold\testrun.txt| ForEach-Object {Get-Mailbox $_ | Get-MailboxStatistics | select @{e={$_.TotalDeletedItemSize.Value + $_.TotalItemSize.Value};l="Size"}| Measure-Object -Property size -Sum| select @{e={$_.Sum / 1GB}} | out-file c:\temp\litigationhold\test-output.txt -append}


    • #178371
      Topics: 10
      Replies: 1375
      Points: 1,481
      Helping Hand
      Rank: Community Hero

      Try taking the calculations and doing them all in the (e)xpression. Also, if you have to output to text, then it should be a CSV and move it out of the FOR loop. Capture all results and then export them, but typically you want to test everything first.

      $results = Get-Content c:\temp\litigationhold\testrun.txt | Select -First 5 | ForEach-Object {

      but you can start with something like this:

      $results = Get-Content c:\temp\litigationhold\testrun.txt | ForEach-Object {
          Get-Mailbox $_ | 
          Get-MailboxStatistics | 
          Select *,
                 @{l="Size";e={ (Measure-Object -InputObject ($_.TotalDeletedItemSize.Value + $_.TotalItemSize.Value) -Property Size -Sum) / 1GB }}
      $results #| Export-CSV -Path C:\LegalHold.csv -NoTypeInformation
Viewing 1 reply thread
  • The topic ‘Formatting Output Dilemma’ is closed to new replies.