EXCHANGE 2007 MAILBOX SIZES

Hi is there a script  in Exchange 2007 to tell me know sizes of users mailbox in MB, item count storage limit, what storage group they are in.

Thank you
happyexchangeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CaptainGibletsCommented:
Here is a script i use to report on my mailbox database.

It exports to a HTML file the columns show, can be ran from any PC as long as the user has rights to run powershell on exchange.

Not all the columns you want are displayed, but can easily be changed by looking at the other columns to show what you want.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://server.domain.local/PowerShell/ -Authentication Kerberos
Remove-Item C:\exchangescripts\DBReport.htm 
New-Item -ItemType file -Path C:\exchangescripts -Name dbreport.htm 
$mailboxCountThreshold =  30 
$mailboxSizeThreshold = 2000 
$mailboxSizeThreshold1 = 1000 
$backupThreshold = 1 
$mbxSizeThreshold = 30MB 
$fileName = "DBReport.htm" 
Function writeHtmlHeader 
{ 
param($fileName) 
$date = ( Get-Date ).ToString('dd/mm/yyyy') 
Add-Content $fileName "<html>" 
Add-Content $fileName "<head>" 
Add-Content $fileName "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>" 
Add-Content $fileName '<title>domain.local Mailbox Reports $date</title>' 
Add-Content $fileName '<STYLE TYPE="text/css">' 
Add-Content $fileName  "<!--" 
Add-Content $fileName  "td {" 
Add-Content $fileName  "font-family: Tahoma;" 
Add-Content $fileName  "font-size: 11px;" 
Add-Content $fileName  "border-top: 1px solid #999999;" 
Add-Content $fileName  "border-right: 1px solid #999999;" 
Add-Content $fileName  "border-bottom: 1px solid #999999;" 
Add-Content $fileName  "border-left: 1px solid #999999;" 
Add-Content $fileName  "padding-top: 0px;" 
Add-Content $fileName  "padding-right: 0px;" 
Add-Content $fileName  "padding-bottom: 0px;" 
Add-Content $fileName  "padding-left: 0px;" 
Add-Content $fileName  "}" 
Add-Content $fileName  "body {" 
Add-Content $fileName  "margin-left: 5px;" 
Add-Content $fileName  "margin-top: 5px;" 
Add-Content $fileName  "margin-right: 0px;" 
Add-Content $fileName  "margin-bottom: 10px;" 
Add-Content $fileName  "" 
Add-Content $fileName  "table {" 
Add-Content $fileName  "border: thin solid #000000;" 
Add-Content $fileName  "}" 
Add-Content $fileName  "-->" 
Add-Content $fileName  "</style>" 
Add-Content $fileName "</head>" 
Add-Content $fileName "<body>" 
Add-Content $fileName  "<table width='100%'>" 
Add-Content $fileName  "<tr bgcolor='#CCCCCC'>" 
Add-Content $fileName  "<td colspan='7' height='25' align='center'>" 
Add-Content $fileName  "<font face='tahoma' color='#003399' size='4'><strong>domain.local Mailbox Report - $date</strong></font>" 
Add-Content $fileName  "</td>" 
Add-Content $fileName  "</tr>" 
Add-Content $fileName  "</table>" 
} 

Function writeTableHeader 
{ 
param($fileName) 
Add-Content $fileName "<table width='100%'><tbody>"  
Add-Content $fileName "<tr bgcolor=#CCCCCC>" 
Add-Content $fileName "<td width='10%' align='center'><B>Database Name</B></td>" 
Add-Content $fileName "<td width='10%' align='center'><b>Username</b></td>" 
Add-Content $fileName "<td width='10%' align='center'><b>Item Count</b></td>" 
Add-Content $fileName "<td width='10%' align='center'><b>Mailbox Size</b></td>"
Add-Content $fileName "<td width='10%' align='center'><b>Deleted Items Size</b></td>"
Add-Content $fileName "<td width='10%' align='center'><b>JunkMail Size</b></td>" 
Add-Content $fileName "<td width='10%' align='center'><b>Last Logon</b></td>" 
Add-Content $fileName "</tr>" 
} 
 

Function WriteInfo
{ 
$mbxs = Invoke-Command -Session $session -ScriptBlock {get-mailboxstatistics -database 'Mailbox Database name'}

$all = @()

foreach($mailbox in $mbxs) 
{ 
   $out = new-object psobject  
   

    
    $out | add-member noteproperty Displayname $mailbox.displayName
    $out | add-member noteproperty LastLogonTime $mailbox.LastLogonTime
	$out | add-member noteproperty db $mailbox.DatabaseName
    $out | add-member noteproperty ItemCount $mailbox.ItemCount
    $TotalItemSize = Invoke-Command -Session $session -ScriptBlock {param($id); (get-mailboxstatistics $id).TotalItemSize.Value.ToMB()} -ArgumentList $mailbox.displayname
    $Deleted = Invoke-Command -Session $session -ScriptBlock {param($id); $di = Get-MailboxFolderStatistics $id -FolderScope DeletedItems; if ($di.count) {$di[0].FolderandSubfolderSize.ToMB()} else {$di.FolderSize.ToMB()}} -ArgumentList $mailbox.displayname
    $Junk = Invoke-Command -Session $session -ScriptBlock {param($id); $di1 = Get-MailboxFolderStatistics $id -FolderScope JunkEmail; if ($di1.count) {$di1[0].FolderandSubfolderSize.ToMB()} else {$di1.FolderSize.ToMB()}} -ArgumentList $mailbox.displayname
    $out | add-member noteproperty TotalItemSize $TotalItemSize
    $out | add-member noteproperty Junk $Junk
    $out | add-member noteproperty Deleted $Deleted   
  
    $all += $out
}

$all =  $all | Sort-Object TotalItemSize -Descending
 foreach ($item in $all)
 {
 
   $ArchiveSize = ''
    $mailboxSizeThreshold = '2000'
    Add-Content $fileName "<table width='100%'><tbody>"  
      Add-Content $fileName "<tr bgcolor=#CCCCCC>"
    Add-Content $fileName ("<td width='10%' align='center'>" + $item.db + "</td>")
      Add-Content $fileName ("<td width='10%' align='center'>" + $item.Displayname + "</td>")
      Add-Content $fileName ("<td width='10%' align='center'>" + $item.ItemCount + "</td>")



    #If it is greater than the table cell will be marked red, else green. 
if ($item.TotalItemSize -gt $mailboxSizeThreshold)
{ 
 	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#FF0000'>" + $item.TotalItemSize + "MB</td>")
} 
elseif ($item.TotalItemSize -gt $mailboxSizeThreshold1)
{ 
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#FF9933'>" + $item.TotalItemSize + "MB</td>")
}
else
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#CCFF33'>" + $item.TotalItemSize + "MB</td>")
}

if ($item.Deleted -gt '200')
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#FF0000'>" + $item.Deleted + "MB</td>")
}
elseif  ($item.Deleted -gt '100')
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#FF9933'>" + $item.Deleted + "MB</td>")
}
Else
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#CCFF33'>" + $item.Deleted + "MB</td>")
}

if ($item.Deleted -gt '200')
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#FF0000'>" + $item.Junk + "MB</td>")
}
elseif  ($item.Deleted -gt '100')
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#FF9933'>" + $item.Junk + "MB</td>")
}
Else
{
	Add-Content $fileName ("<td width='10%' align='center' td bgcolor='#CCFF33'>" + $item.Junk + "MB</td>")
}
	Add-Content $fileName ("<td width='10%' align='center'>" + $item.LastLogonTime + "</td>")
    Add-Content $fileName "</tr>"

}
}
writeHtmlHeader $fileName
writeTableHeader $fileName
WriteInfo $fileName
Remove-PSSession $Session

Open in new window

0
RadweldCommented:
Yes, you can simply run in Powershell the following.

Get-Mailbox | Get-MailBoxStatistics | FT DisplayName, ItemCount, StorageLimitStatus, TotalItemSize - AutoSize | Export-Csv c:\mailboxsize.csv

The Export-CSV command exports the results into a CSV so you can review the output in Excel




0
RadweldCommented:
If you amend the command to as follows,

Get-MailBox | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | FT DisplayName, ItemCount, StorageLimitStatus, TotalitemSize -Autosize

Open in new window


This will sort the output by the size of the mailbox is descending order.

If you add | Export-CSV C:\mailboxsize.csv again, this will create a CSV file and export the results to it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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

happyexchangeAuthor Commented:
Hi i tried that script and got this error message/  Please advice

[PS] C:\Documents and Settings\admin.jamiec>Get-Mailbox | Get-MailBoxStatistics
| FT DisplayName, ItemCount, StorageLimitStatus, TotalItemSize - AutoSize | Expo
rt-Csv c:\mailboxsize.csv
Format-Table : A positional parameter cannot be found that accepts argument '-'
.
At line:1 char:41
+ Get-Mailbox | Get-MailBoxStatistics | FT <<<<  DisplayName, ItemCount, Storag
eLimitStatus, TotalItemSize - AutoSize | Export-Csv c:\mailboxsize.csv
    + CategoryInfo          : InvalidArgument: (:) [Format-Table], ParameterBi
   ndingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
   .Commands.FormatTableCommand
0
CaptainGibletsCommented:
are you running the script in the exchange management shell? As it is correct.
0
RadweldCommented:
In the Error, its showing a space separating the hyphen with the word Autosize. You need to remove this space so it reads -Autosize
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.