Solved

Exchange 2010 get-mailbox and get-mailboxstatistics

Posted on 2016-08-06
10
442 Views
Last Modified: 2016-08-09
Hi,
I am trying to do some auditing to get all mailboxes primary email addresses , aliases and mailbox sizes.
I have run below script and get primary and aliases email addresses, but it does not give me mailbox sizes.
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}, @{Name="TotalSize"; Expression={get-mailboxstatistics $_.displayname | Select-object TotalItemSize}} | Export-CSV c:\temp\smtp.csv

Open in new window

0
Comment
Question by:jzrobbie
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 25

Expert Comment

by:-MAS
ID: 41745387
Please check my article which will give you name, PrimarySmtpAddress, DatabaseQuotaenabled, TotalItemSize, ProhibitSendQuota, ProhibitSendReceiveQuota, IssueWarningQuota, DBIssueWarningQuota, DBProhibitSendQuota, DBProhibitSendReceiveQuota
https://gallery.technet.microsoft.com/exchange/Email-statistics-including-e9cb1b26
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 41745439
Try changing $_.displayname to simply $PSItem
I believe there's a common property between those two cmdlets, so it should work...
0
 
LVL 25

Expert Comment

by:-MAS
ID: 41745652
You can try this if you want to pipe get-mailbox and get-mailboxstatistics together
Get-Mailbox -ResultSize Unlimited | sort-object | Select-Object DisplayName, Alias, PrimarySMTPAddress,EmailAddresses,@{n="MailboxSizeMB";e = {$MBXstat = Get-MailboxStatistics $_.Displayname; $MBXstat.TotalItemSize.Value.ToMB()}}

Open in new window

0
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 

Author Comment

by:jzrobbie
ID: 41745959
@MAS, Thank you for the script. but How can I export to CSV file without adding multiple headers?
I have modified your script a bit , but it shows the item size is "-", still can't figure out why.

Get-Mailbox -ResultSize Unlimited -server NXT17|
Select-Object DisplayName,ServerName,PrimarySmtpAddress, `
@{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}, `
@{Name="size";Expression={if ((Get-Mailboxstatistics $_.alias).TotalItemSize.Value)`
{(Get-Mailboxstatistics $_.alias).TotalItemSize.Value.ToMB()}else{"-"}}} |
more

Open in new window

0
 

Author Comment

by:jzrobbie
ID: 41745968
@sirbounty

Changed to $PSItem ,it still shows blank output for TotalItemSize column
Capture.PNG
0
 
LVL 25

Accepted Solution

by:
-MAS earned 250 total points
ID: 41745971
If you want to export you can use this
Get-Mailbox -ResultSize Unlimited | sort-object | Select-Object DisplayName, Alias, PrimarySMTPAddress,EmailAddresses,@{n="MailboxSizeMB";e = {$MBXstat = Get-MailboxStatistics $_.Displayname; $MBXstat.TotalItemSize.Value.ToMB()}} | Export-Csv C:\temp\smtp.csv

Open in new window

0
 

Author Comment

by:jzrobbie
ID: 41745980
@MAS

It worked!!!

Sort-Object dose the job.

Can you tell me why we need to sort the output before piping to get-mailboxstatistics?
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 125 total points
ID: 41746145
Depending on your powershell version (v3 and above support $PSItem) - you may still need to use $_
0
 

Author Comment

by:jzrobbie
ID: 41748195
Thank you guys for the help, problem solved.
0
 
LVL 12

Assisted Solution

by:Benjamin Voglar
Benjamin Voglar earned 125 total points
ID: 41748717
I am using this script to get statistic:

just for info ;)

$Mailboxes = Get-Mailbox -ResultSize Unlimited
 foreach ($Mailbox in $Mailboxes)
 {
 $Mailbox | Add-Member -MemberType “NoteProperty” -Name “MailboxSizeMB” -Value ((Get-MailboxStatistics $Mailbox).TotalItemSize.Value.ToMb())
 }
 $Mailboxes | Sort-Object MailboxSizeMB -Desc | Select PrimarySMTPAddress, MailboxSizeMB

#REM – to export this out — do the following ;) enjoy (see the part where it says “Select” you can add additional fields like ALIAS etc to this)

$Mailboxes = Get-Mailbox -ResultSize Unlimited
 foreach ($Mailbox in $Mailboxes)
 {
 $Mailbox | Add-Member -MemberType “NoteProperty” -Name “MailboxSizeMB” -Value ((Get-MailboxStatistics $Mailbox).TotalItemSize.Value.ToMb())
 }
 
$nname="MailBoxSize"
$date=(get-date).dayofyear
$path="c:\IT\"
$prefix=".csv"
$exportname=$path+$nname+$date+$prefix

$Mailboxes | Sort-Object MailboxSizeMB -Desc | Select DisplayName, PrimarySMTPAddress, MailboxSizeMB | Export-Csv -NoType $exportname

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to install and use the NTBackup utility that comes with Windows Server.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
how to add IIS SMTP to handle application/Scanner relays into office 365.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question