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!
PowershellExchange

Avatar of undefined
Last Comment
fireguy1125

8/22/2022 - Mon
Justin Yeung

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/Programming/Languages/Scripting/Powershell/Q_28211456.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"
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

Justin Yeung

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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
fireguy1125

ASKER
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
fireguy1125

ASKER
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
Justin Yeung

what version of powershell do you have?

get-host | ft version
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Justin Yeung

try this instead

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

Open in new window

fireguy1125

ASKER
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

Justin Yeung

can you post the entire script that you are running?

and the $GB line is not needed anymore.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
fireguy1125

ASKER
$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

Justin Yeung

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.
fireguy1125

ASKER
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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Justin Yeung

Allocated LUN size, isn't the total space assigned to a logical drive?
fireguy1125

ASKER
No, this will be a static value on what is actually provisioned from the storage array.
Justin Yeung

Your storage array is from a SAN?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
fireguy1125

ASKER
Yes
Justin Yeung

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

ASKER
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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Justin Yeung

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

fireguy1125

ASKER
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
Justin Yeung

would you mind to post the entire script again, so then I can tell where the issue is.
Your help has saved me hundreds of hours of internet surfing.
fblack61
fireguy1125

ASKER
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

Justin Yeung

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
fireguy1125

ASKER
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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Justin Yeung

try to put " " in front and after the 0.

$WhiteSpaceDiff = "0"
$edbVolumeDIff = "0"
fireguy1125

ASKER
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

Justin Yeung

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
fireguy1125

ASKER
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
Justin Yeung

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
fireguy1125

ASKER
Thank you for all your persistent help, it is greatly appreciated!