Scenario: You want a script that will combine the Alias from the get-mailbox command and the Mailbox Size (TotalItemSize and TotalDeletedItemSize) from the get-mailboxstatistics command into a single array variable. You want to export the Results to a .csv file as well.
Script:
$db = get-mailboxdatabase $final = @() $file = "C:tempAlias_Size.csv" $db | Select -expandproperty Name | Sort | %{ Write-Host "DBName: $_ " -ForegroundColor Cyan $mbx = Get-mailbox -database $_ -resultsize unlimited $mbx | Select -expandpropert alias | Sort | %{ Write-Host ".......... Pulling Stats for $_" -ForegroundColor Yellow $alias = $_ $size = Get-mailboxstatistics $alias | Select TotalItemSize,TotalDeletedItemSize $TIS = $size.TotalItemSize $TDIS = $size.TotalDeletedItemSize $ServerObj = New-Object PSObject $ServerObj | Add-member NoteProperty -Name "Alias" -Value $alias $ServerObj | Add-Member NoteProperty -name "TIS" -Value $TIS $ServerObj | Add-Member NoteProperty -name "TDIS" -Value $TDIS $final += $ServerObj } } $final | Export-csv $file -append