Link to home
Start Free TrialLog in
Avatar of fireguy1125
fireguy1125

asked on

Modify Exchange 2010 Database Statistics Powershell Script

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!
Avatar of Justin Yeung
Justin Yeung
Flag of United States of America image

I believe your script was copied from the link below however you didn't post the function portion from your script above. the Get-dbvolume will not be available
https://www.experts-exchange.com/questions/28211456/Exchange-2010-Disk-Space-and-Database-Powershell-Script-Scheduled-Task.html

function Get-DBVolume([string] $FilePath, [string] $Server){
    do
    {
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\') + 1)
        $wmiFilter = ('Name="{0}"' -f $FilePath.Replace("\", "\\"))
        $volume = get-wmiobject -class win32_volume -computername $Server -filter $wmiFilter
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\'))
    } while ($volume -eq $null)
    return $volume
}


1. Line 4
$WhiteSpace = $DB.AvailableNewMailboxSpace.toGB()

2. Line 18
DatabaseSize = ("{0:N2}" -f $DB.DatabaseSize.toTB()) + " TB"

3 Line 19
WhiteSpace = ("{0:N2}" -f  $WhiteSpace) + " GB"

4. Line 20
"Available Disk Space" = $edbVolumeFreeSpace + " GB"

5 Line 22
"Change in Disk Space" = ("{0:N2}" -f $edbVolumeDIff) + " GB"

6 Line 23
WhiteSpaceDiff = ("{0:N2}" -f $WhiteSpaceDiff) + " GB"
Avatar of fireguy1125
fireguy1125

ASKER

Thanks, I'm getting an error when running the script:

Cannot convert value " GB" to type "System.Double". Error: "Input string was not in a correct format."
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:48
+     "Available Disk Space" = $edbVolumeFreeSpace + <<<<  " GB"
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException


I've included the scripted as it is now:

$Statfile = "C:\TempStats.csv"

function Get-DBVolume([string] $FilePath, [string] $Server){
    do
    {
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\') + 1)
        $wmiFilter = ('Name="{0}"' -f $FilePath.Replace("\", "\\"))
        $volume = get-wmiobject -class win32_volume -computername $Server -filter $wmiFilter
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\'))
    } while ($volume -eq $null)
    return $volume 
}

If (Test-Path $Statfile) {$Stat = Import-Csv $Statfile}

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

		$WhiteSpace = $DB.AvailableNewMailboxSpace.toGB()
		$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 = ("{0:N2}" -f $DB.DatabaseSize.toTB()) + " TB"
	WhiteSpace = ("{0:N2}" -f  $WhiteSpace) + " GB"
	"Available Disk Space" = $edbVolumeFreeSpace + " GB"
        logVolumeFreeSpace = [math]::Round((((Get-DBVolume $($db.LogFolderPath.pathname+"\") $db.Servername).FreeSpace).FreeSpace /1GB),2)
	"Change in Disk Space" = ("{0:N2}" -f $edbVolumeDIff) + " GB"
	WhiteSpaceDiff = ("{0:N2}" -f $WhiteSpaceDiff) + " GB"
	} 
}) | Select DBName,ServerName,DatabaseSize,WhiteSpace,"Available Disk Space","Change in Disk Space",WhiteSpaceDiff

$body | Export-Csv $Statfile -NTI

Open in new window

try to add [string] in front of " GB"

"Available Disk Space" = $edbVolumeFreeSpace + [string]" GB"

Open in new window


since $edbVolumeFreeSpace is [int] --- it was set to [math] on the top.

or if that does work

try this

add
$GB = "GB"  #on top of line 35

Open in new window

and then
"Available Disk Space" = $edbVolumeFreeSpace $GB

Open in new window


see if that work
When I add this line:

"Available Disk Space" = $edbVolumeFreeSpace + [string]" GB"

It gives me an error:

Cannot convert value " GB" to type "System.Double". Error: "Input string was not in a correct format."
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:48
+     "Available Disk Space" = $edbVolumeFreeSpace + <<<<  [string]" GB"
    + CategoryInfo          : NotSpecified: (:) [], RuntimeException
    + FullyQualifiedErrorId : RuntimeException
When I add the other 2 lines:

$GB = "GB"  #on top of line 35
"Available Disk Space" = $edbVolumeFreeSpace $GB

I get this error:

Unexpected token 'GB' in expression or statement.
At C:\Scripts\ExchangeDBStatusEmail.ps1:36 char:50
+     "Available Disk Space" = $edbVolumeFreeSpace $GB <<<<
    + CategoryInfo          : ParserError: (GB:String) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken
what version of powershell do you have?

get-host | ft version
try this instead

"Available Disk Space" = $($edbVolumeFreeSpace  |out-string)[0] + " GB"

Open in new window

Version 2.0

I applied your change, and still getting error messages:

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Index operation failed; the array index evaluated to null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:35 char:2
+      <<<< $GB = "GB"  #on top of line 35
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\Scripts\ExchangeDBStatusEmail.ps1:43 char:19
+ $body | Export-Csv <<<<  $Statfile -NTI
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

Open in new window

can you post the entire script that you are running?

and the $GB line is not needed anymore.
$Statfile = "C:\TempStats.csv"

function Get-DBVolume([string] $FilePath, [string] $Server){
    do
    {
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\') + 1)
        $wmiFilter = ('Name="{0}"' -f $FilePath.Replace("\", "\\"))
        $volume = get-wmiobject -class win32_volume -computername $Server -filter $wmiFilter
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\'))
    } while ($volume -eq $null)
    return $volume 
}

If (Test-Path $Statfile) {$Stat = Import-Csv $Statfile}

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

		$WhiteSpace = $DB.AvailableNewMailboxSpace.toGB()
		$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 = ("{0:N2}" -f $DB.DatabaseSize.toTB()) + " TB"
	WhiteSpace = ("{0:N2}" -f  $WhiteSpace) + " GB"
	$GB = "GB"  #on top of line 35
	"Available Disk Space" = $($edbVolumeFreeSpace  |out-string)[0] + " GB"
        logVolumeFreeSpace = [math]::Round((((Get-DBVolume $($db.LogFolderPath.pathname+"\") $db.Servername).FreeSpace).FreeSpace /1GB),2)
	"Change in Disk Space" = ("{0:N2}" -f $edbVolumeDIff) + " GB"
	WhiteSpaceDiff = ("{0:N2}" -f $WhiteSpaceDiff) + " GB"
	} 
}) | Select DBName,ServerName,DatabaseSize,WhiteSpace,"Available Disk Space","Change in Disk Space",WhiteSpaceDiff

$body | Export-Csv $Statfile -NTI

$a = "<style>"
$a = $a + "BODY{font-family: Courier New; font-size: 11pt; background-color:White;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: white;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: white;background-color:#B8B8B8}"
$a = $a + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: white;background-color:Cream}"
$a = $a + "</style>"

$messageParameters = @{
Subject = "Exchange Database Size Report " + (Get-Date -Format g)
body = $Body | ConvertTo-Html -Head $a -As List | Out-String
From = "alert@domain.com" 
To = "emailadmin@domain.com"
SmtpServer = "mail.domain.com"
BodyAsHtml = $true
}

Send-MailMessage @messageParameters

Open in new window

just remove line 37

and you might want to change the path from c:\ on line 1 to a valid path

to a writeable path, sometime c:\ path is restricted.
Thanks, removing line 37 resolved the issue and the script completes.

One remaining question from the original request is:

-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)?

I would just specify this value in the script itself, but would just need to know how to include it in the email report.

Thanks again for your persistence and follow-up, it is greatly appreciated.
Allocated LUN size, isn't the total space assigned to a logical drive?
No, this will be a static value on what is actually provisioned from the storage array.
Your storage array is from a SAN?
Yes
so you want to have a manual fill in space for that?

another word, you want to have  "Allocated LUN Size" with empty data on that csv file or email?
Yes,
For example, my e-mail report includes the following information:

DBName:      Database1
ServerName:      EXCH2010A
DatabaseSize:      1.00 TB
WhiteSpace:      27.00 GB
Available Disk Space:      1 GB
Change in Disk Space:      -156.68 GB
WhiteSpaceDiff:      GB


I would like to manual entry add a row called: Allocated LUN Size: 1.5TB to be included among the other data that is actually querying for information.
easy then

just add "Allocated LUN Size" = "whatever you what" # in between
New-Object PSOBject -Property @{
	DBName = $DB.Name
	ServerName = $DB.ServerName
	DatabaseSize = ("{0:N2}" -f $DB.DatabaseSize.toTB()) + " TB"
	WhiteSpace = ("{0:N2}" -f  $WhiteSpace) + " GB"
	"Allocated LUN Size" = "1.5 TB"
	"Available Disk Space" = $($edbVolumeFreeSpace  |out-string)[0] + " GB"
        logVolumeFreeSpace = [math]::Round((((Get-DBVolume $($db.LogFolderPath.pathname+"\") $db.Servername).FreeSpace).FreeSpace /1GB),2)
	"Change in Disk Space" = ("{0:N2}" -f $edbVolumeDIff) + " GB"
	WhiteSpaceDiff = ("{0:N2}" -f $WhiteSpaceDiff) + " GB"
	} 

Open in new window


and then add "Allocated LUN Size" after the code below

| Select DBName,ServerName,DatabaseSize,WhiteSpace,"Available Disk Space","Change in Disk Space",WhiteSpaceDiff,"Allocated LUN Size"

Open in new window

I don't know what happened, but the Change in Disk Space, Available Disk Space and WhiteSpaceDiff rows are showing invalid or incomplete data:

DBName:      Database1
ServerName:      Exchange1
DatabaseSize:      1.00 TB
WhiteSpace:      26.00 GB
Available Disk Space:      1 GB
Change in Disk Space:      -156.01 GB
WhiteSpaceDiff:      GB
would you mind to post the entire script again, so then I can tell where the issue is.
Sure, appreciate it:

$Statfile = "C:\TempStats.csv"

function Get-DBVolume([string] $FilePath, [string] $Server){
    do
    {
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\') + 1)
        $wmiFilter = ('Name="{0}"' -f $FilePath.Replace("\", "\\"))
        $volume = get-wmiobject -class win32_volume -computername $Server -filter $wmiFilter
        $FilePath = $FilePath.Substring(0, $FilePath.LastIndexOf('\'))
    } while ($volume -eq $null)
    return $volume 
}

If (Test-Path $Statfile) {$Stat = Import-Csv $Statfile}

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

		$WhiteSpace = $DB.AvailableNewMailboxSpace.toGB()
		$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 = ("{0:N2}" -f $DB.DatabaseSize.toTB()) + " TB"
	WhiteSpace = ("{0:N2}" -f  $WhiteSpace) + " GB"
	"Available Disk Space" = $($edbVolumeFreeSpace  |out-string)[0] + " GB"
        logVolumeFreeSpace = [math]::Round((((Get-DBVolume $($db.LogFolderPath.pathname+"\") $db.Servername).FreeSpace).FreeSpace /1GB),2)
	"Change in Disk Space" = ("{0:N2}" -f $edbVolumeDIff) + " GB"
	WhiteSpaceDiff = ("{0:N2}" -f $WhiteSpaceDiff) + " GB"
	} 
}) | Select DBName,ServerName,DatabaseSize,WhiteSpace,"Available Disk Space","Change in Disk Space",WhiteSpaceDiff

$body | Export-Csv $Statfile -NTI

$a = "<style>"
$a = $a + "BODY{font-family: Courier New; font-size: 11pt; background-color:White;}"
$a = $a + "TABLE{border-width: 2px;border-style: solid;border-color: white;border-collapse: collapse;}"
$a = $a + "TH{border-width: 2px;padding: 0px;border-style: solid;border-color: white;background-color:#B8B8B8}"
$a = $a + "TD{border-width: 2px;padding: 0px;border-style: solid;border-color: white;background-color:Cream}"
$a = $a + "</style>"

$messageParameters = @{
Subject = "Exchange Database Size Report " + (Get-Date -Format g)
body = $Body | ConvertTo-Html -Head $a -As List | Out-String
From = "exchangealert@company.com" 
To = "exchangeadmin@company.com"
SmtpServer = "mail.company.com"
BodyAsHtml = $true
}

Send-MailMessage @messageParameters

Open in new window

do you have the existing file on the C drive?

$Statfile = "C:\TempStats.csv"

it uses the existing data for showing the difference from last run.

if you delete the file, it should give you the correct current info
Thanks, I deleted the file, re-ran the report yesterday, and again this morning, and still see the accurate changes are not being reflected as they should, and are appearing the same way which I posted before.
try to put " " in front and after the 0.

$WhiteSpaceDiff = "0"
$edbVolumeDIff = "0"
Did that, I get the following errors:

Bad numeric constant: 25.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (25.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 25.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (25.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 30.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (30.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 29.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (29.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 62.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (62.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 3.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (3.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 34.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (34.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Open in new window

change line WhiteSpace = ("{0:N2}" -f  $WhiteSpace) + " GB"
to WhiteSpace = ("{0:N2}" -f  $WhiteSpace)

and add "WhiteSpace in GB" = ("{0:N2}" -f  $WhiteSpace) + " GB"

add "WhiteSpace in GB" under select at line 43.

it doesn't know how to read the $stat file with " GB" on it, so add another property to isolate the issue.
Thanks, I've performed the changes, and still getting the error:
Bad numeric constant: 25.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (25.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 25.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (25.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 29.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (29.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 28.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (28.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 61.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (61.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 3.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (3.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 0.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (0.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Bad numeric constant: 35.00 GB.
At C:\Scripts\ExchangeDBStatusEmail.ps1:22 char:69
+         $WhiteSpaceDiff = ($Stat | ?{$_.DBname -eq $DB.Name}).WhiteSpace - <<<<  $WhiteSpace
    + CategoryInfo          : InvalidOperation: (35.00 GB:String) [], RuntimeException
    + FullyQualifiedErrorId : BadNumericConstant

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Justin Yeung
Justin Yeung
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for all your persistent help, it is greatly appreciated!