Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 4, 2011 3:52 AM
Hi all. I would like to generate a report of all user's mailbox information from Get-Mailbox and Get-MailboxStatistics. How can I combine into one command? Right now, I have to run two commands, and combine them using Excel.
Get-Mailbox | Select ExchangeGuid, UserPrincipalName, DataBase | Export-CSV c:\temp\test1.csv
Get-MailboxStatistics | Select ExchangeGuid, TotalItemSize | Export-CSV c:\temp\test2.csv
Please help. Thank you!
All replies (2)
Wednesday, May 4, 2011 5:13 AM ✅Answered
#have no exchange on my MAC at the moment( ;-) ), butif u can use the guid like that "Get-MailboxStatistics ExchangeGuid" than the below might work...
$Mailboxes = Get-Mailbox | Select ExchangeGuid, UserPrincipalName, DataBase
foreach($mailbox in $Mailboxes)
{
$totalitemsize = Get-MailboxStatistics $mailbox.ExchangeGuid | Select TotalItemSize
write-output "$mailbox.ExchangeGuid ,$mailbox.UserPrincipalName ,$mailbox.DataBase ,$totalitemsize "
}
Wednesday, May 4, 2011 7:47 AM ✅Answered
You "merge" the objects by creating a new object and define the properties from each variable:
Get-Mailbox -ResultSize Unlimited | Foreach-Object{
$mbx = $_ | Select ExchangeGuid, UserPrincipalName, DataBase
$stats = Get-MailboxStatistics $_ | Select ExchangeGuid, TotalItemSize
New-Object -TypeName PSObject -Property @{
ExchangeGuid = $mbx.ExchangeGuid
UserPrincipalName = $mbx.UserPrincipalName
DataBase = $mbx.DataBase
ExchangeGuid = $stats.ExchangeGuid
TotalItemSize = $stats.TotalItemSize
}
} | Export-Csv c:\temp\test.csv -NoTypeInformation
Shay Levy [MVP]
PowerShay.com
PowerShell Toolbar