Collect Exchange 2007 CCR Database Sizes
Updated, cheers for letting me know, please be aware the text gets wrapped on the blog so if you get any errors first try on makesure each line of code are the lines beginning with $
# Identity is the full exchange path to the database ie MBXClusterA\MBXClusterA-SG1\MBXClusterA-DB1
#Node name is either of the CCR cluster nodes#
# Headers of CSV identity,Nodename#
Add-PSSnapin Microsoft.Exchange.Management.Powershell.Admin
$SourceFile = "c:\CCRDatabases.csv"
$servers = Import-Csv $SourceFile
$results =@()
foreach ($db in $servers)
{
$identity = $Db.identity
$Nodename = $Db.Nodename
$results += Get-MailboxDatabase $identity | Select-Object server,storagegroup,Identity, @{Name="Size";Expression={$objitem = (Get-MailboxDatabase $Identity); $path = "`\`\" + $Nodename + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, @{Name="Sizeb";Expression={$objitem = (Get-MailboxDatabase $Identity); $path = "`\`\" + "$Nodename" + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $sizeb = ((Get-ChildItem $path).length)/1024KB; [math]::round($sizeb, 2)}}, @{Name="Mailbox";expression={(Get-Mailbox -Database $Identity -resultsize unlimited | Measure-Object).Count}}
}
$results | export-csv -path c:\martin.csv
{
Write-Host All Done!!
}
$Nodename = $Db.Nodename
$results += Get-MailboxDatabase $identity | Select-Object server,storagegroup,Identity, @{Name="Size";Expression={$objitem = (Get-MailboxDatabase $Identity); $path = "`\`\" + $Nodename + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, @{Name="Sizeb";Expression={$objitem = (Get-MailboxDatabase $Identity); $path = "`\`\" + "$Nodename" + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $sizeb = ((Get-ChildItem $path).length)/1024KB; [math]::round($sizeb, 2)}}, @{Name="Mailbox";expression={(Get-Mailbox -Database $Identity -resultsize unlimited | Measure-Object).Count}}
}
$results | export-csv -path c:\martin.csv
{
Write-Host All Done!!
}


I ran this script and getting an error with the @{>$path. It errors out expecting ';', '}' or end-of-line, not
>.
$results += Get-MailboxDatabase $identity | Select-Object server,storagegroup,Identity, @{>$path = "`\`\" + $Nodename + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName..Remove(0,2);`
PS] C:\Exch2k7SP2\scripts>& '.\RayDatabaseSizeStep 11.ps1'
Expected ';', '}' or end-of-line, not
>.
At C:\Exch2k7SP2\scripts\RayDatabaseSizeStep 11.ps1:17 char:92
+ $results += Get-MailboxDatabase $identity | Select-Object server,storagegroup
,Identity, @{>$ <<<< path = "`\`\" + $Nodename + "`\" + $objItem.EdbFilePath.Dr
iveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName..Remove(0,2);
Reply to this
Hi thanks for pointing it out, seems the original post left some of the script out.
M
Reply to this
Hi did you manage to get the script working in your environment
Reply to this
I did not get it working. This is the error I am getting with you latest script posted. I am running this on Exchange 2007 SP2 RU2 CCR cluster
Import-Csv : Cannot open file C:\CCRDatabases.csv.
At C:\Exch2k7SP2\scripts\MadferretDatabaseScript.ps1:6 char:22
+ $servers = Import-Csv <<<< $SourceFile
Select-Object : You cannot call a method on a null-valued expression.
Reply to this
Hi mate
First have you created the import csv with the required information?
If you have did you save it as C:\CCRDatabases.csv
THe csv needs the following
Column called identity with the path to each database MBXClusterA\MBXClusterA-SG1\MBXClusterA-DB1
Column called Nodename with the name of one of the cluster nodes.
Remember because the text is wrapped you may need to tweak the script so that it reads correcly
keep me posted
Reply to this
I created the CCRDatabases.csv and included the columns. I am having a problem with the path. I have tried different paths. The path for one of the databases is.
c:\Program Files\Microsoft\Exchange Server\Mailbox\First Storage Group\mtl-sg1-mailboxdatabase.edb
Also the CMS name for cluster is MTLTSTEMS1.
Get-MailboxDatabase : A parameter cannot be found that matches parameter name '
MTLTSTEMS1\Program Files\Microsoft\Exchange Server\mailbox\first storage group\
mtl-sg1-mailboxdatabase'.
Reply to this
Ran your script below to find path but still have a problem with syntax.
Thought this was useful to help determine my syntax error with path.
foreach ($server in Get-MailboxServer)
{
foreach ($objItem in Get-MailboxDatabase -server $server)
{
$edbfilepath = $objItem.edbfilepath
$dbpath = $EdbFilePath.PathName.Remove(0,2).remove($EdbFilePath.PathName.length-6)
$mailboxpath = “$server$dbpath”
write-host $server.name $mailboxpath
}
}
Output from Script for Database Path
mtltstems1 mtltstems1\Program Files\Microsoft\Exchange Server\Mailbox\First Stor
age Group\mtl-sg1-mailboxdatabase
Reply to this
to get the database path needed go to powershell and type
Get-mailboxdatabase | Select identity
For the Node name DONT use the cluster name, it needs to be the name of one CCR node
Reply to this
That worked perfect. How do I email this output so I can view this in outlook in HTML?
Reply to this
I added this code but when I run it get an error saying that martin.csv is being used by another process.
$file = New-Item -type file "c:\martin.csv" -force
function sendmail([string] $body)
{
$SmtpClient = new-object system.net.mail.smtpClient
$MailMessage = New-Object system.net.mail.mailmessage
$SmtpClient.Host = "149.83.60.88"
$mailmessage.from = "MailboxDatabaseSizeReport@donotreply.com"
$mailmessage.To.add("raymond.dales@broadridge.com")
$mailmessage.Subject = "Mailbox Database Size Report"
$mailmessage.Body = $body
$MailMessage.IsBodyHtml = $TRUE
$smtpclient.Send($mailmessage)
}
$allservers |export-csv $file -NoTypeInformation
$body = "Mailbox database size report for $date"
$bodydetail = $allservers |sort-object "Server\StorageGroup\Database" |convertto-html
$body = $body + $bodydetail
sendmail $body
Reply to this
IF you run it from a batch file it should release the CSV so that you can right over it.
Have a look at the section
http://blog.meigh.eu/2010/02/24/running-powershell-script-as-scheduled-task.aspx
I run it on a schedule that calls the batch file.
No had a chance to check the html,, from what you have posted seems your on track.
If you get it working can you post please.
Cheers
M
Reply to this
Thanks for the corrections, but I am still getting problems with syntax. No consistent error message. Interesting to see what other people are trying..
Reply to this
hi mate
drop me an email with you script you are running, a copy of the import file and I will have a look.
Cheers
martin@meigh.eu
Reply to this
I'm still not having any luck with it. Have you had a lot of feedback from readers since early March? Would be curious to know what others say about their experiences and where you are in the process of writing code that works.
Reply to this
send me you import file and i will review. The script I have works. I used it at a number of customer sites.
Reply to this
Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!
Reply to this
I really thankful to you for this great read!! You did a very great job, keep it up.
Reply to this