Formatting Output Dilemma

Welcome Forums General PowerShell Q&A Formatting Output Dilemma

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #178305

    Participant
    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

    Participant
    Topics: 8
    Replies: 1213
    Points: 756
    Helping Hand
    Rank: Major Contributor

    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
    

You must be logged in to reply to this topic.