We help IT Professionals succeed at work.
Get Started

Modify Exchange 2010 Database Statistics Powershell Script

fireguy1125
fireguy1125 asked
on
605 Views
Last Modified: 2014-05-20
I need assistance with modifying my powershell script.  It gathers statistics of disk space and mailbox database sizes from my Exchange environment and sends it in an e-mail.  I have included a snippet of what I would like cleaned up:

-Need $Whitespace output to be in GB, rounded to 2 decimal places (like the edbvolume free space is)

-Need DatabaseSize output to be in TB, rounded to 2 decimal places

-Need to include in the output a single space and the letters TB after the databasesize value (for example 1.50 TB)

-Need Whitespace, Available Disk Space, Change in Disk Space, WhiteSpaceDiff output to be in GB, rounded to 2 decimal places and need to include in this output a single space and the letters DB after these values

-Additionally, I would like to include a static manual entry called "Allocated LUN Size". How can in Include this in my results (which in another portion of the script get output to a table)?

$body = $(Foreach ($DB in (Get-MailboxDatabase -Status | Sort-Object Name | 
		?{$_.Mounted -eq $True -and (Test-Connection $_.ServerName -Count 2 -Quiet)})) {

		$WhiteSpace = $DB.AvailableNewMailboxSpace.toMB()
		$edbVolumeFreeSpace = [math]::Round(((Get-DBVolume $DB.EdbFilePath.pathname $DB.ServerName).FreeSpace /1GB),2)
		If ($Stat -ne $null) {
		$WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - $WhiteSpace
		$edbVolumeDIff = ($Stat | ?{$_.DBname -eq $DB.Name}).edbVolumeFreeSpace - $edbVolumeFreeSpace
		}
		Else{
		$WhiteSpaceDiff = 0
		$edbVolumeDIff = 0
		}

	New-Object PSOBject -Property @{
	DBName = $DB.Name
	ServerName = $DB.ServerName
	DatabaseSize = $DB.DatabaseSize
	WhiteSpace = $WhiteSpace
	"Available Disk Space" = $edbVolumeFreeSpace
        logVolumeFreeSpace = [math]::Round((((Get-DBVolume $($db.LogFolderPath.pathname+"\") $db.Servername).FreeSpace).FreeSpace /1GB),2)
	"Change in Disk Space" = "{0:N2}" -f $edbVolumeDIff
	WhiteSpaceDiff = "{0:N2}" -f $WhiteSpaceDiff
	} 
}) | Select DBName,ServerName,DatabaseSize,WhiteSpace,"Available Disk Space","Change in Disk Space",WhiteSpaceDiff

Open in new window



Thank you for your assistance!
Comment
Watch Question
Senior Systems Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 30 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE