• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 697
  • Last Modified:

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
0
happyexchange
Asked:
happyexchange
  • 3
  • 2
2 Solutions
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now