# Formatting Output Dilemma

**URL:** <https://forums.powershell.org/t/formatting-output-dilemma/13164>\
**Category:** PowerShell Help\
**Created:** [September 19, 2019, 6:55am UTC](https://forums.powershell.org/t/formatting-output-dilemma/13164 "2019-09-19T06:55:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigal007](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@bigal007](https://forums.powershell.org/u/bigal007)\
**Post date:** [September 19, 2019, 6:55am UTC](https://forums.powershell.org/t/formatting-output-dilemma/13164/1 "2019-09-19T06:55:18Z")

</div>

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}
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 19, 2019, 8:59am UTC](https://forums.powershell.org/t/formatting-output-dilemma/13164/2 "2019-09-19T08:59:49Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/formatting-output-dilemma/13164/3 "2024-05-16T20:31:22Z")

</div>


