Solved

Exchange 2010 get-mailbox and get-mailboxstatistics

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

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In this video we show how to create a Contact 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 Recipients >> Contact ta…
how to add IIS SMTP to handle application/Scanner relays into office 365.

863 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

26 Experts available now in Live!

Get 1:1 Help Now