header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Exchange Mailbox Database size
Last Post 02 Dec 2008 06:18 PM by KarlMitschke. 57 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Page 1 of 212 > >>
Author Messages
michael_hysenUser is Offline
New Member
New Member
Posts:2

--
08 Feb 2008 01:04 PM  

OK, I know this should not be hard but I am at a loos on how to do this.  How do I accurately report on the size of the Exchange 2007 mailbox database?  I can of course take the size of everyones mailbox and sum it, but the size this reflects does not seem to show the real DB size.  And I would rather not just take the file size (free space and all that).

marco.shawUser is Online
Co-Community Director
Basic Member
Basic Member
Posts:181

--
08 Feb 2008 05:27 PM  
Good question. I don't see this as a property of the get-mailboxdatabase cmdlet. I don't see a way to get this from Exchange Web Services either. I migth ask another forum if they know.
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
08 Feb 2008 05:40 PM  
Michael;

Try this (borrowed and modified from Professional Windows PowerShell for Exchange Server 2007 SP1)

$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
foreach ($server in $exchangeservers)
{
$db = Get-MailboxDatabase -server $server
foreach ($objItem in $db)
{
$edbfilepath = $objItem.edbfilepath
$path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
$dbsize = Get-ChildItem $path
$dbname = $objitem.identity |SELECT parent,name
$dbname = $dbname.Parent.ToString() + "`\" + $dbname.Name.ToString()
$output = "Server " + $server + ", Database " + $dbname +", Size(KB) " + $dbsize.Length
Write-Output $output
}
}
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
08 Feb 2008 08:00 PM  
OK, Never one to let sleeping exchange scripts alone, I have modified this one:

#REQUIRES -pssnapin Microsoft.Exchange.Management.PowerShell.Admin
$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
foreach ($server in $exchangeservers)
{
$db = Get-MailboxDatabase -server $server
foreach ($objItem in $db)
{
$edbfilepath = $objItem.edbfilepath
$path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
$dbsize = Get-ChildItem $path
[float]$size = $dbsize.Length /1024/1024
$dbname = $objitem.identity |SELECT parent,name
$dbname = $dbname.Parent.ToString() + "`\" + $dbname.Name.ToString()
$output = "Server: " + $server + ", Database: " + $dbname +", Size: " + $size + " (GB)"
Write-Output $output
}
}
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
08 Feb 2008 10:18 PM  
Once more, into the vortex :)

This is an updated script that is also in the book "Professional Windows PowerShell for Exchange Server 2007 SP1", slightly modified, to retrieve all mailbox databases, and to run from any workstation with the EMS:


$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    Write-Output $ReturnedObj 
    }
}
michael_hysenUser is Offline
New Member
New Member
Posts:2

--
11 Feb 2008 01:33 PM  
Hi Karl,

Fantastic, works well. My next challenge will be to format this nicely as a report I can make available. I'll keep you posted.
mdgrayUser is Offline
New Member
New Member
Posts:5

--
18 Mar 2008 11:46 AM  
Great script. Works really well.

Would like to run it automatcially and have it email me which I have working for the Mailbox users list for all databases. I would like to modify the code to direct the output to an inline email. Any suggestions. Not having much luck.

Apologies if this is a nwebie question. Have not coded in a a long time!!!
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
20 Mar 2008 07:57 PM  
This should get you started:

$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$AllServers = @()
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    $AllServers += $ReturnedObj
    }
}
$ALLServers = $AllServers.Replace("@{","")
$ALLServers = $AllServers.Replace("}","`n")
function sendmail($body)
{
    $SmtpClient = new-object system.net.mail.smtpClient 
    $MailMessage = New-Object system.net.mail.mailmessage 
    $SmtpClient.Host = "<your mail host>" 
    $mailmessage.from = "spamfree@donotreply.com" 
    $mailmessage.To.add("<Your Email Address") 
    $mailmessage.Subject = “Exchange 2007 Database Sizes” 
    $MailMessage.IsBodyHtml = $false
    $mailmessage.Body = $body
    
    $smtpclient.Send($mailmessage) 
}

sendmail $ALLServers
mjh40aUser is Offline
New Member
New Member
Posts:7

--
20 Mar 2008 09:43 PM  

How about to kick out to a csv file?  I'd like to import this into SQL but am beating my head on the wall trying to output the text untruncated in a nice csv format.  I'm not certain where I can add the pipe for export-csv.  Any help would be great!

Excellent script :)

Thanks!

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
20 Mar 2008 10:21 PM  
Here you go:


$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$AllServers = @()
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    $AllServers += $ReturnedObj
    }
}

$AllServers |export-csv c:\test.csv -notype -force
mjh40aUser is Offline
New Member
New Member
Posts:7

--
21 Mar 2008 01:03 PM  

Perfect!

Thanks :)

mjh40aUser is Offline
New Member
New Member
Posts:7

--
21 Mar 2008 02:03 PM  
How about adding a Mailbox Count as an additional column? This would be a good check on how many mailboxes per store...

Thanks!
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
21 Mar 2008 05:15 PM  
Your wish is my command:


$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$AllServers = @()
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
    $dbpath = $EdbFilePath.PathName.Remove(0,2).remove($EdbFilePath.PathName.length-6)
    $mailboxpath = "$server$dbpath"
    $mailboxcount = Get-MailboxStatistics -database $mailboxpath |measure-object
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    $ReturnedObj | Add-Member NoteProperty -Name "Mailbox Count" -Value $mailboxcount.count
    $AllServers += $ReturnedObj
    }
}

$AllServers |export-csv c:\test.csv -notype -force
mjh40aUser is Offline
New Member
New Member
Posts:7

--
21 Mar 2008 05:42 PM  

Thanks!

Any idea on this error:

Get-MailboxStatistics : Cannot bind parameter 'Database'. Cannot convert value
"EX2007D\Program Files\Microsoft\Exchange Server\Mailbox\Fifth Storage Group\Ma
ilbox Database 5" to type "Microsoft.Exchange.Configuration.Tasks.DatabaseIdPar
ameter". Error: "'EX2007D\Program Files\Microsoft\Exchange Server\Mailbox\Fifth
 Storage Group\Mailbox Database 5' is not a valid value for the identity.
Parameter name: Identity"
At C:\scripts\database_size3.ps1:16 char:52
+     $mailboxcount = Get-MailboxStatistics -database  <<<< $mailboxpath |measu
re-object

It seems to not like the -database option for some reason...

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
21 Mar 2008 05:50 PM  
Are you pasting this into a powershell console?

If so, tell me what this returns:

$server
$db
$edbfilepath
$path
$mailboxpath

Karl
mjh40aUser is Offline
New Member
New Member
Posts:7

--
21 Mar 2008 06:08 PM  

Here you go.  I'm only listing one storage group result per variable but it does return these results for each database:

$server=EX2007D

$db=Mailbox Database     EX2007D         First Storage Group  False
Mailbox Database 3   EX2007D         Third Storage Group  False
Mailbox Database 4   EX2007D         Fourth Storage Group False
Mailbox Database 5   EX2007D         Fifth Storage Group  False

$edbpath=IsPathInRootDirectory : False
PathName              : C:\Program Files\Microsoft\Exchange Server\Mailbox\Fift
                        h Storage Group\Mailbox Database 5.edb
IsLocalFull           : True
IsUnc                 : False
DriveName             : C:
ServerName            :

$path=\\EX2007D\C$\Program Files\Microsoft\Exchange Server\Mailbox\Fifth Storage Grou
p\Mailbox Database 5.edb

$mailboxpath=EX2007D\Program Files\Microsoft\Exchange Server\Mailbox\Fifth Storage Group\Mai
lbox Database 5

Thanks!

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
21 Mar 2008 06:25 PM  
Try this command:

Get-MailboxStatistics -database "$mailboxpath" |measure-object
mjh40aUser is Offline
New Member
New Member
Posts:7

--
21 Mar 2008 06:51 PM  

get-mailboxstatistics -database "EX2007D\Program Files\Microsoft\Exchange Server\Mailbox\Fifth Storage Group\Mailbox Database 5"   gives me the error in the previous post.

get-mailboxstatistics -database "EX2007D\Mailbox Database 5" Works!

Could a variable be defined for just the database name?

Thanks!

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
21 Mar 2008 07:45 PM  
OK, try this:


$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$AllServers = @()
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $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
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
    $ReturnedObj | Add-Member NoteProperty -Name "Mailbox Count" -Value $mailboxcount.count
    $AllServers += $ReturnedObj
    }
}

$AllServers |export-csv c:\test.csv -notype -force



Karl
mjh40aUser is Offline
New Member
New Member
Posts:7

--
21 Mar 2008 08:05 PM  
Bingo! Thanks!
mdgrayUser is Offline
New Member
New Member
Posts:5

--
04 Apr 2008 01:32 AM  
Thanks Karl for the code. I had to make one change to the emailed Database size list you posted above for it to work for me.

$ALLServers = $AllServers.Replace("@{","")
$ALLServers = $AllServers.Replace("}","`n")

I had to changeto:

$ALLServers = $AllServers -replace("@{","")
$ALLServers = $AllServers -replace("}","`n")

That sorted my issues. Thanks for your help.
ChronUser is Offline
New Member
New Member
Posts:2

--
08 Apr 2008 06:35 PM  
The script Karl has created here is great. The one thing that I have noticed is that it includes all mailboxes (including the disabled mailboxes). is it possible using a Where filter or something to get this so that the mailbox Count portion excludes the Disabled Mailboxes from the count. I have been looking around and I cant find a command to get a list of all the objects that can be filtered by so as to do this myself.

The programming background that I have did get me to a point where I was able to rework this script to work specific to my site and to get me all kinds of data besides just the size and count but this one piece has me stumped.
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
08 Apr 2008 09:19 PM  

Try replacing the line

$mailboxcount = Get-MailboxStatistics -database "$mailboxpath"  |measure-object



With this one:

$mailboxcount = Get-MailboxStatistics -database "$mailboxpath"  |Where {$_.DisconnectDate -eq $null} |measure-object



Karl

ChronUser is Offline
New Member
New Member
Posts:2

--
09 Apr 2008 12:45 PM  
Thanx Karl. Of course just like always as soon as I finished posting here looking for the answer I found the variable I was looking for. Good to know that the variable that I found was the same one you listed here.

Thanx Again.
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
09 Apr 2008 02:29 PM  
That happens to me all the time, too :)
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
09 Apr 2008 04:10 PM  

I saw an emailed question from mdgray asking: "Could the same code be used to leave out the System Mailboxes as well as the disabled accounts?"
I don't see the question here, anymore, but:

$mailboxcount = Get-MailboxStatistics -database "$mailboxpath"  |Where {$_.DisconnectDate -eq $null -and $_.ObjectClass -eq 'Mailbox'} |measure-object

My whole script is now:

##############################################################
#                                                            #
# Script to show the size and mailbox count of all databases #
#                                                            #
#                Karl Mitschke 4/9/2008                      #
#                                                            #
##############################################################

$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true }
$AllServers = @()
foreach ($server in $exchangeservers)
{
    $db = Get-MailboxDatabase -server $server
    foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)
    $dbsize = Get-ChildItem $path
	$dbpath = $EdbFilePath.PathName.Remove(0,2).remove($EdbFilePath.PathName.length-6)
	$mailboxpath = "$server$dbpath"
	$mailboxcount = Get-MailboxStatistics -database "$mailboxpath"  |Where {$_.DisconnectDate -eq $null -and $_.ObjectClass -eq 'Mailbox'} |measure-object
	$disconnectedmailboxcount = Get-MailboxStatistics -database "$mailboxpath"  |Where {$_.DisconnectDate -ne $null} |measure-object
    $ReturnedObj = New-Object PSObject
    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity
    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))
	$ReturnedObj | Add-Member NoteProperty -Name "User Mailbox Count" -Value $mailboxcount.count
	$ReturnedObj | Add-Member NoteProperty -Name "Disconnected Mailbox Count" -Value $disconnectedmailboxcount.count
    $AllServers += $ReturnedObj
    }
}

$AllServers |export-csv c:\test.csv -notype -force
mdgrayUser is Offline
New Member
New Member
Posts:5

--
09 Apr 2008 10:41 PM  
Karl,

Thanks for replying, I have so many scripts I got confused. The question was actually for a script I have modified to display all the users, item count, Mailboxsize and Last login from all Exchange servers in the Organisation and emails it. The code you have provided is a better way than the way I have done it. So thanks again. If anyone is interested the script, let me know and I can post.

Matt
albogadoUser is Offline
New Member
New Member
Posts:4

--
08 May 2008 05:17 PM  

Karl,

Thanks for the script, however I am not seeing User Mailbox Count or Disconnected Mailbox Count in my output?  I get the DBs and DB size just fine.  It appears as though my path is being truncated for some reason.

"Get-MailboxStatistics : The specified mailbox database "CHMSG03\SG3DB\CHMSG03SG3DB1" does not exist.
At line:12 char:54"

The actual path is "CHMSG03\CHMSG0SG3DB\CHMSG03SG3DB"

 

 Any thoughts?  Thanks

 

Garion

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:161

--
08 May 2008 05:54 PM  
Garion;

Your server is named CHMSG03, correct? do this:

$db = Get-MailboxDatabase -server "CHMSG03"
foreach ($objItem in $db)
    {
    $edbfilepath = $objItem.edbfilepath
    $dbpath = $EdbFilePath.PathName.Remove(0,2).remove($EdbFilePath.PathName.length-6)
    write-output "edbfilepath" $edbfilepath
    write-output "dbpath" $dbpath
    }

post the results, and I will look into it

Karl
albogadoUser is Offline
New Member
New Member
Posts:4

--
08 May 2008 06:51 PM  

Thanks Karl!  My mistake, these are the correct paths as verified by the output from your command and a quick visual;

F:\SG3DB\CHMSG03SG3DB1.edb
F:\SG1DB\CHMSG03SG1DB1.edb
F:\SG2DB\CHMSG03SG2DB1.edb
F:\SG4DB\CHMSG03SG4DB1.edb
F:\SG5DB\CHMSG03SG5DB1.edb
F:\SG6DB\CHMSG03SG6DB1.edb
F:\SG7DB\CHMSG03SG7DB1.edb
F:\SG8DB\CHMSG03SG8DB1.edb
F:\SG9DB\CHMSG03SG9DB1.edb
F:\SG10DB\CHMSG03SG10DB1.edb
F:\SG11DB\CHMSG03SG11DB1.edb
F:\SG12DB\CHMSG03SG12DB1.edb
F:\SG13DB\CHMSG03SG13DB1.edb
F:\SG14DB\CHMSG03SG14DB1.edb
F:\SG15DB\CHMSG03SG15DB1.edb
F:\SG16DB\CHMSG03SG16DB1.edb
F:\SG17DB\CHMSG03SG17DB1.edb
F:\SG18DB\CHMSG03SG18DB1.edb
F:\SG19DB\CHMSG03SG19DB1.edb
F:\SG20DB\CHMSG03SG20DB1.edb
F:\SG21DB\CHMSG03SG21DB1.edb

I'm not getting any other errors other than these for each DB so I'm not sure why I'm not getting the MBX count and Disconnected count;

 At line:12 char:54
+     $disconnectedmailboxcount = Get-MailboxStatistics  <<<< -database "$mailboxpath"  |Where {$_.DisconnectDate -ne $
null} |measure-object
Get-MailboxStatistics : The specified mailbox database "CHMSG02\SG1DB\CHMSG02SG1DB1" does not exist.

 

You are not authorized to post a reply.
Page 1 of 212 > >>


Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer