Powershell / Exchange 2007 – sum in MB of all mailboxes, deleted elements, .edb file and white spaces for a storage group

Some time ago, I had a need to determine some of storage groups parameters from Exchange 2007, that need become more frequent than I thought, and here is that script.

The script wll return those values like in 3th line of it, so there will be: Storage group name, sum of all mailboxes (in megabytes), sum of all deleted items (in megabytes), size of the *.edb database file, and the amount of white space in each storage group.

$data = Get-Date –f "yyyy-MM-dd";
$MailboxServer = "Here enter the name of your mailbox server"
out-file -filepath StorageGroupsReport_$data.txt -append -inputobject "Storage GRoup Name ($elem);Sum for all mailboxes (MB) ($suma);Sum of all deleted elements (MB) ($sumdel);Database file size (MB) ($sumadb);Sum of White Space (MB) ($SG_WS)"

foreach ($elem in Get-MailboxDatabase){
	$elem
	$SG_MB = (Get-Mailbox -ResultSize Unlimited -Database "$elem" |  get-mailboxstatistics  | measure-object totalitemsize -sum)
	$suma = "{0:N2}" -f ($SG_MB.sum / 1MB)

	$SGdel_MB = (Get-Mailbox -ResultSize Unlimited -Database "$elem" |  get-mailboxstatistics  | measure-object totaldeleteditemsize -sum)
	$sumadel = "{0:N2}" -f ($SGdel_MB.sum / 1MB)

	$SGDB_MB = (Get-MailboxDatabase "$elem" | 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 / 1mb),2)) -passthru}  | measure-object mailboxdbsizeinGB -sum)
	$sumadb = "{0:N2}" -f ($SGDB_MB.sum)

	$dt = $elem.name
	$s = (get-eventlog Application -ComputerName $MailboxServer -instanceID 1074136261 -Message "*$dt*" -newest 1 | select -expand message )
	$d = ($s.IndexOf(" megabytes") - $s.IndexOf("`has "))
	$SG_WS = ($s.Substring($s.IndexOf("has "),$d).trim("has "))
	$SG_WS
	out-file -filepath StorageGroupsReport_$data.txt -append -inputobject "$elem;$suma;$sumadel;$sumadb;$SG_WS"
}
Advertisements

2 thoughts on “Powershell / Exchange 2007 – sum in MB of all mailboxes, deleted elements, .edb file and white spaces for a storage group

  1. Do you thoughts if I quote a few your posts as long as I offer credit and sources back to your web site? My blog website is in the exact same niche as yours and my visitors would definitely benefit from some of the information you offer here. Please allow me know if this alright with you. Regards!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s