Solved

Exchange 2010 get-mailbox and get-mailboxstatistics

Posted on 2016-08-06
10
166 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 24

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 24

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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now