The collected information is:
- Server name
- Database path and filename
- Database Size
- Mailboxes by database
- Disk Size
- Free space on disk
- Percentage of free space
#----------------------------------------------
# Capacity Planning Report for Exchange v1.0
# Author: Fernando Ezequiel Hazzan
# Date: 3/2/2010
#----------------------------------------------
# Get Servers Information
$servers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$serversreport = @()
# Look into each server for needed data
foreach ($server in $servers)
{
# Get database list from current server
$db = Get-MailboxDatabase -server $server
# Work on each database
foreach ($objitem in $db)
{
# Get storage information of current database
$driveinfo = Get-WMIObject -class "Win32_LogicalDisk" -namespace "root\CIMV2" -computername $server -filter ("Caption = '" + $objitem.EdbFilePath.DriveName + "' ")
$drivefreespace = ($driveinfo.FreeSpace/1MB).tostring("0.00")
$drivecapacity = ($driveinfo.Size/1MB).tostring("0.00")
$percent = ($driveInfo.FreeSpace * 100.0)/$driveinfo.Size
$percent = ("{0:N0}" -f $percent) + "%"
# Get size information of the current database
$edbfilepath = $objitem.edbfilepath
$path = "`\`\" + $server + "`\" + $objitem.EdbFilePath.DriveName.Remove(1).ToString() + "$" + $objitem.EdbFilePath.PathName.Remove(0,2)
$dbsize = Get-ChildItem $path
$start = $path.LastIndexOf('\')
$dbpath = $path.Substring($start +1).remove($path.Substring($start +1).length -4)
$mailboxpath = "$server\$dbpath"
$mailboxcount = Get-MailboxStatistics -database "$mailboxpath" |measure-object
# Create a sheet and insert the information needed
$sheet = New-Object PSObject
$sheet | Add-Member NoteProperty -Name "Server" -Value $server
$sheet | Add-Member NoteProperty -Name "Database" -Value $objItem.edbfilepath.pathname
$sheet | Add-Member NoteProperty -Name "Size(MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
$sheet | Add-Member NoteProperty -Name "Mailboxes" -Value $mailboxcount.count
$sheet | Add-Member NoteProperty -Name "Disk Size(MB)" -Value $drivecapacity
$sheet | Add-Member NoteProperty -Name "Free Spice(MB)" -Value $drivefreespace
$sheet | Add-Member NoteProperty -Name "% Free" -Value $percent
# Add the sheet of this database to the report string
$serversreport += $sheet
}
}
# Export the report to a CSV file
$serversreport |Export-CSV ((Get-Date -uformat "%m-%d-%Y") +".csv") -notype -force