Get Exchange Server Database Size and Mailbox Size
This is something you would be simple, and it is, if you know the commands. Unfortunately if you have an Exchange 2007 it is different than a 2010.
In my environment I have both so my script decides which it is and spits out the report for 2007 or 2010.
One of the reasons I am writing this is to DRILL into my head that these scripts MUST be run as administrator, not run by an administrator.. I mean Right Click the powershell and "Run As Administrator". If you do not run as administrator your database will return 0. Yes it returns 0.
So.. here is the script. Enjoy.
Get-MailboxStatistics -Server $env:computername
| Select DisplayName,
ItemCount,
TotalItemSize |
Sort-Object TotalItemSize
-Descending |
Export-CSV C:\temp\MBSizes.csv
$TheVersion = Get-ExchangeServer
| select *
if ($TheVersion.AdminDisplayVersion.major
-like "14"){$version14 =
"yes"
Get-MailboxDatabase
-Status | select ServerName,Name,DatabaseSize
| Export-CSV
C:\temp\DBSize.csv
}
else {
Get-MailboxDatabase
| foreach-object
{add-member -inputobject
$_ -membertype
noteproperty -name
mailboxdbsizeinGB -value ([math]::Round(([int64](get-wmiobject cim_datafile -computername
$_.server
-filter ('name='''
+ $_.edbfilepath.pathname.replace("\","\\")
+ '''')).filesize / 1GB),2)) -passthru} | Sort-Object mailboxdbsizeinGB
-Descending |
select identity,mailboxdbsizeinGB
| Export-CSV
-NoTypeInformation C:\temp\DBSize.csv
}
No comments:
Post a Comment