Solved

Get Mailbox Sizes

Posted on 2014-11-24
20
118 Views
Last Modified: 2014-12-10
I'm trying to run a command through EMS to obtain a listing of mailbox sizes for all users in our exchange environment.  Typically I'd use the following command.  What I'd like to include is along with displayname is the Primary SMTP address and to convert the size to a standard unit such as mb or GB.  Any help in this would be greatly appreciated.



0
Comment
Question by:georgedschneider
  • 8
  • 7
  • 2
  • +1
20 Comments
 
LVL 13

Expert Comment

by:imkottees
ID: 40463670
Hi,

here you go...
Get-MailboxStatistics -Server 'SERVERNAME' | where {$_.ObjectClass -eq “Mailbox”} | Sort-Object TotalItemSize -Descending | ft @{label=”User”;expression={$_.DisplayName}},@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}}  -auto >> “c:\Temp\mailbox_size.txt”

you won't get primary smtp address as it is not a parameter of mailbox statistics. You can export it from get-mailbox properties and do a match using display name.
0
 

Author Comment

by:georgedschneider
ID: 40463709
What do you mean by do a match against displayname?
0
 
LVL 12

Expert Comment

by:Md. Mojahid
ID: 40463781
Get-MailboxDatabase -Status | Select-Object Name,@{N="DatabaseSize GB";E={"$([math]::round($_.DatabaseSize.Tobytes() /1Gb, 2)) GB"}},AvailableNewMailboxSpace | Sort-Object Name | fl
0
Problems using Powershell and Active Directory?

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

 
LVL 13

Expert Comment

by:imkottees
ID: 40463840
I meant, export users primary smtp address and displayname from Get-Mailbox and displayname, size from Get-MailboxStatistics. Then using excel macth the displayname to combine both.
0
 
LVL 12

Expert Comment

by:Md. Mojahid
ID: 40463846
Actually by: marahman3001 you got me really close. I figured it out. You dont need the loop in your script. It works great just breaking the command into two parts.

Part One:
assign a variable the entire report that is sorted by mailbox size

$mailboxreport = Get-MailboxDatabase | get-mailboxstatistics | sort-object -property totalitemsize -descending

Part Two:
export the data that that variable holds into a CSV file.

$mailboxreport | select-object displayname, itemcount, @{ expression={$_.TotalItemSize.Value.ToKB()} } , lastloggedonuser, lastlogontime, lastlogofftime, servername, databasename | export-csv c:\userstats.csv

For more
http://exchangeserverpro.com/powershell-tip-get-list-top-exchange-server-mailboxes-size/

http://smtp25.blogspot.in/2009/01/how-to-export-user-mailboxes-and-its_12.html
0
 

Author Comment

by:georgedschneider
ID: 40465265
Is it not possible to get the primary smtp address as well in one report?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40481056
Try this..
Get-Mailbox -ResultSize Unlimited | Select Displayname,Primarysmtpaddress,@{N="totalitemsizeGB";E={'{0:f2}' -f (($_ | Get-MailboxStatistics).TotalItemSize.Value.ToBytes()/1GB)}}

Open in new window

To export the result to csv file..
Get-Mailbox -ResultSize Unlimited | Select Displayname,Primarysmtpaddress,@{N="totalitemsizeGB";E={'{0:f2}' -f (($_ | Get-MailboxStatistics).TotalItemSize.Value.ToBytes()/1GB)}} | Export-Csv C:\report.csv -nti

Open in new window

0
 

Author Comment

by:georgedschneider
ID: 40481579
The Total Item size is blank
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40481602
Does it work when you run against a single user?
Get-Mailbox UserA | Select Displayname,Primarysmtpaddress,@{N="totalitemsizeGB";E={'{0:f2}' -f (($_ | Get-MailboxStatistics).TotalItemSize.Value.ToBytes()/1GB)}}

Open in new window

0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40481661
If above command works then try..
$(Foreach ($Mailbox in (Get-Mailbox -ResultSize Unlimited)){
$Size = Get-MailboxStatistics $Mailbox.Alias | Select @{N="totalitemsizeGB";E={'{0:f2}' -f ($_.TotalItemSize.Value.ToBytes()/1GB)}}
	New-Object PSObject -Property @{
		Displayname = $Mailbox.Displayname
		Primarysmtpaddress = $Mailbox.Primarysmtpaddress
		totalitemsizeGB = $Size.totalitemsizeGB
	}
})| Export-Csv C:\report.csv -nti

Open in new window

0
 

Author Comment

by:georgedschneider
ID: 40481843
What does the New-Object PSObject do?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40481905
It is used to create a custom object..

There are many ways to create a custom object in PowerShell, you can refer following article for details..
http://technet.microsoft.com/en-us/magazine/hh750381.aspx
0
 

Author Comment

by:georgedschneider
ID: 40483536
Can you sort by DisplayName or one of the custom objects?
0
 

Author Comment

by:georgedschneider
ID: 40483979
One question.  This works great in our on premise exchange 2010 SP3 environment.  The problem I run into is when I run it against an Office 365 hosted Exchange environment the mailbox size shows blank.  Any thought why this would occurr in Office 365?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40484119
It should work for office 365 also.. Try changing line 2 to following and see if it makes any difference..
$Size = $Mailbox | Get-MailboxStatistics | Select @{N="totalitemsizeGB";E={'{0:f2}' -f ($_.TotalItemSize.Value.ToBytes()/1GB)}}

Open in new window

0
 

Author Comment

by:georgedschneider
ID: 40487306
0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 40487869
Probably, but I will not be able to test it right now. you can try replacing the code with following line and see if it works for you...
$Size = $Mailbox | Get-MailboxStatistics | Select @{N="totalitemsizeGB";E={[math]::Round( ($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1GB),2)}}

Open in new window

0
 

Author Comment

by:georgedschneider
ID: 40490079
This code worked with one weird issue.  The item count field is being displayed after Name even though its coded after mailbox size.




$(Foreach ($Mailbox in (Get-Mailbox -ResultSize Unlimited)){
$size = Get-MailboxStatistics $Mailbox.Alias | Select DisplayName,@{name="TotalI<wbr ></wbr>temSizeMB"<wbr ></wbr>;expressio<wbr ></wbr>n={[math]:<wbr ></wbr>:Round(($_<wbr ></wbr>.TotalItem<wbr ></wbr>Size.ToStr<wbr ></wbr>ing().Spli<wbr ></wbr>t("(")[1].<wbr ></wbr>Split(" ")[0].Replace(",","")/1MB)<wbr ></wbr>,0)}},Item<wbr ></wbr>Count 
New-Object PSObject -Property @{
        Name = $Mailbox.Displayname
        "Email Address" = $Mailbox.Primarysmtpaddres<wbr ></wbr>s
        "Mailbox Size" = $Size.totalitemsizeMB
        ItemCount = $Size.itemcount
          }
})

Open in new window

0
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 40490232
You can fix it by selecting the object properties in order.. for example..
$(Foreach ($Mailbox in (Get-Mailbox -ResultSize Unlimited)){

#your code here...

}) | Select-Object Name,"Email Address","Mailbox Size",ItemCount

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

806 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