This script lists the database sizes in our environment. Not only the used space is retrieved, but the whitespace and the number of mailboxes is displayed in each databases as well.
When data is deleted from a database - either by a user, purging messages from their mailboxes, or by admins deleting, moving whole mailboxes - the physical size of the EDB database file doesn't change, it does not shrink. The deleted data will leave a white space behind, that will be filled up by new messages and mailboxes.
If you need to reclaim the freed up space by shrinking the EDB file, getting back space in the filesystem, please check the article here
The Script:
# Get mailbox count for each databases $mailboxes =Get-Mailbox -Filter * -ResultSize Unlimited | Group-Object -Property Database # Get database size and whitespace Get-MailboxDatabase -Status | %{ $db = $_.Name $server = $_.ServerName $mb = ($mailboxes | ?{$_.name -like $db}).Count $size = ($_.DatabaseSize.split("( ")[3].replace(",",""))/[math]::pow(1024,3) $whitespace = $_.AvailableNewMailboxSpace.split("( ")[3].replace(",","")/[math]::pow(1024,3) # Export the results on screen and in CSV format too write-host -f green "$db`t$server`t-`t$size with whitespace: $whitespace" [pscustomobject]@{name=$db; server=$server; mailboxes=$mb; size=$size; whitespace=$whitespace} | Export-Csv "database-sizes$((get-date).month)$((get-date).day).csv" -Append -NoTypeInformation }
Comments