InfrastrucutureServices
asked on
Add available WhiteSpace report to diskspace report for Exchange 2007 mountpoints
Hi,
This code (kindly updated on Experts Exchange) shows low disk space on Exchange mount points, I would like it to include the available whitespace as an additional column as well.
This is the main report and below that is the script we currently use for Whitepsace:
Whitespace:
Thanks in advance
This code (kindly updated on Experts Exchange) shows low disk space on Exchange mount points, I would like it to include the available whitespace as an additional column as well.
This is the main report and below that is the script we currently use for Whitepsace:
function get-mountpoints {
param( $server )
[decimal]$threshold = 20
$TotalGB = @{Name="Capacity(GB)";expression={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{Name="FreeSpace(GB)";expression={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
$volumes = Get-WmiObject -ComputerName $server -Class win32_volume | Where-object {$_.DriveLetter -eq $null}
$volumes | select systemname, label, $TotalGB, $FreeGB, $FreePerc | ?{$_."Free(%)" -lt $threshold} |ConvertTo-Html | Out-String
}
$messageParameters = @{
Subject = "Exchange DiskSpace Report " + (Get-Date -Format g)
body = (Get-Content c:\batch\diskspace2\servers.txt | ForEach-Object {
get-mountpoints $_
} ) | out-string
From = "exchangereports@company.com"
To = "myself@company.com"
SmtpServer = "smtp.com"
BodyAsHtml = $true
}
Send-MailMessage @messageParameters
Whitespace:
# Get-ExchangeWhitespace.ps1
# This script creates a CSV report listing the available whitespace in each database in the Org
# Thanks goes out to Shay Levy for the hard work
# Convert Dates to WMI CIM dates
$tc = [System.Management.ManagementDateTimeconverter]
$Start =$tc::ToDmtfDateTime( (Get-Date).AddDays(-2).Date )
$End =$tc::ToDmtfDateTime( (Get-Date).Date)
# Create two calculated properties for InsertionStrings values
$Database = @{Name="Database";Expression={$_.InsertionStrings[1]}}
$FreeMB = @{Name="FreeMB";Expression={[int]$_.InsertionStrings[0]}}
# Get all Exchange servers in the Org except Edge servers
$ExchangeServers = ("server1","server2","server3")
# Connect to each server's App log and get data from 1221 events in the last day
ForEach ($Computername in $ExchangeServers) {
write-host "Collecting data from $Computername..."
$Whitespace += Get-WMIObject Win32_NTLogEvent -Computername $Computername -Filter "LogFile='Application' AND EventCode=1221 AND TimeWritten>='$Start' AND TimeWritten<='$End'" | Select-Object ComputerName,$Database,$FreeMB | Sort-Object FreeMB –Unique –Descending | Select-Object ComputerName, Database, FreeMB
}
# Export the results
Write-Host "Results exported to 'Exchange Whitespace.csv'"
$Whitespace | Export-Csv "Exchange Whitespace.csv" -NoTypeInformation -ErrorAction SilentlyContinue
Thanks in advance
Are you trying to attach the Whitespace csv file to the mount point report email?
ASKER
No, if possible I would prefer that the available whitespace is added as an additional column to the main email.
eg:
systemname label Capacity(GB) FreeSpace(GB) Free(%) WhiteSpace(GB)server1 SG2T 250 43.44 17 20
The idea being even if i see a low disk space alert, i will know if there is enough whitepspace free so I don't have to worry too much.
eg:
systemname label Capacity(GB) FreeSpace(GB) Free(%) WhiteSpace(GB)server1 SG2T 250 43.44 17 20
The idea being even if i see a low disk space alert, i will know if there is enough whitepspace free so I don't have to worry too much.
This is a bit tricky.. Do you have more than one database in one volume?
Try this and see if it works as expected...
[decimal]$threshold = 20
function Get-DBMountPoints([string] $FilePath, [string] $Server)
{
$TotalGB = @{N="Capacity(GB)";E={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{N="FreeSpace(GB)";E={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{N="Free(%)";E={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
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)
$volume | select Systemname, label, $TotalGB, $FreeGB, $FreePerc
}
$DBInfo = Get-ExchangeServer | ?{$_.ServerRole -match "Mailbox"} | % {
$logs = Get-EventLog application -computername $_.Name | ? {$_.Eventid -eq 1221} | Sort TimeGenerated |
Select TimeGenerated,@{N="Database";E={$_.ReplacementStrings[1]}},@{N="FreeMB";E={$_.ReplacementStrings[0]}}
Foreach ($DB in Get-MailboxDatabase -Server $_.Name){
New-Object PSObject -Property @{
Server = $DB.Server
Database = "$DB"
"WhiteSpace(MB)" = ($logs | ?{$_.Database -match $DB.Name} | Sort TimeGenerated -Descending | Select -First 1).FreeMB
}
}
} | Select Server,Database,"WhiteSpace(MB)"
$Body = $DBInfo | % {
$WhiteSpace = $_."WhiteSpace(MB)"
$Database = $_.Database
$DBPath = (Get-MailboxDatabase $Database).EdbFilePath.Pathname -Split "\\"
$DBPath = $DBPath[0..($DBPath.length - 2)] -join "\"
Get-DBMountPoints $DBPath $_.Server | Select *,@{N="Database";E={$Database}},@{N="WhiteSpace(MB)";E={$WhiteSpace}}
} | Select Systemname, label, "Capacity(GB)", "FreeSpace(GB)", "Free(%)",Database,"WhiteSpace(MB)" |
?{$_."Free(%)" -lt $threshold} | ConvertTo-Html | Out-String
$messageParameters = @{
Subject = "Exchange DiskSpace Report " + (Get-Date -Format g)
body = $Body
From = "exchangereports@company.com"
To = "myself@company.com"
SmtpServer = "smtp.com"
BodyAsHtml = $true
}
Send-MailMessage @messageParameters
ASKER
There is only one DB per mountpoint.
I tried your code, that errored with get-eventlog : the network path was not found 20: char:22 $logs = get-eventog <<< application - computername ......
I guessed this might be because of trying to access over 100+ Exchange servers, some of which over very low connections and some where the account would have no permissions.
I tried this to cut it down to just the ones I wanted using:
$DBInfo = Get-ExchangeServer | ?{$_.ServerRole -match "Mailbox" -and $_.name -like "*70*"}
That has been running for about 2 hours now with no sign of finishing, could we try using the server list from the original script ?
I tried your code, that errored with get-eventlog : the network path was not found 20: char:22 $logs = get-eventog <<< application - computername ......
I guessed this might be because of trying to access over 100+ Exchange servers, some of which over very low connections and some where the account would have no permissions.
I tried this to cut it down to just the ones I wanted using:
$DBInfo = Get-ExchangeServer | ?{$_.ServerRole -match "Mailbox" -and $_.name -like "*70*"}
That has been running for about 2 hours now with no sign of finishing, could we try using the server list from the original script ?
Ok... I have made some changes and you can add the servers manually in line 2..
[decimal]$threshold = 20
$ExchangeServers = ("server1","server2","server3")
function Get-DBMountPoints([string] $FilePath, [string] $Server)
{
$TotalGB = @{N="Capacity(GB)";E={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{N="FreeSpace(GB)";E={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{N="Free(%)";E={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
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)
$volume | select Systemname, label, $TotalGB, $FreeGB, $FreePerc
}
$DBInfo = $ExchangeServers | % {
$logs = Get-EventLog application -computername $_ -After (get-date).Adddays(-7) -InstanceId 1221 | Sort TimeGenerated |
Select TimeGenerated,@{N="Database";E={$_.ReplacementStrings[1]}},@{N="FreeMB";E={$_.ReplacementStrings[0]}}
Foreach ($DB in Get-MailboxDatabase -Server $_){
New-Object PSObject -Property @{
Server = $DB.Server
Database = "$DB"
"WhiteSpace(MB)" = ($logs | ?{$_.Database -match $DB.Name} | Sort TimeGenerated -Descending | Select -First 1).FreeMB
}
}
} | Select Server,Database,"WhiteSpace(MB)"
$Body = $DBInfo | % {
$WhiteSpace = $_."WhiteSpace(MB)"
$Database = $_.Database
$DBPath = (Get-MailboxDatabase $Database).EdbFilePath.Pathname -Split "\\"
$DBPath = $DBPath[0..($DBPath.length - 2)] -join "\"
Get-DBMountPoints $DBPath $_.Server | Select *,@{N="Database";E={$Database}},@{N="WhiteSpace(MB)";E={$WhiteSpace}}
} | Select Systemname, label, "Capacity(GB)", "FreeSpace(GB)", "Free(%)",Database,"WhiteSpace(MB)" |
?{$_."Free(%)" -lt $threshold} | ConvertTo-Html | Out-String
$messageParameters = @{
Subject = "Exchange DiskSpace Report " + (Get-Date -Format g)
body = $Body
From = "exchangereports@company.com"
To = "myself@company.com"
SmtpServer = "smtp.com"
BodyAsHtml = $true
}
Send-MailMessage @messageParameters
ASKER
Added three servers in, it gave the same error, hung for about 20 minutes then delivered an empty email:
This was the error:
[PS] C:\batch\diskspace2>.\incw hitespace. ps1
Get-EventLog : No matches found
At C:\batch\diskspace2\incwhi tespace.ps 1:21 char:22
+ $logs = Get-EventLog <<<< application -computername $_ -After (get-date)
.Adddays(-7) -InstanceId 1221 | Sort TimeGenerated |
+ CategoryInfo : ObjectNotFound: (:) [Get-EventLog], ArgumentExce
ption
+ FullyQualifiedErrorId : GetEventLogNoEntriesFound, Microsoft. PowerShell .C
ommands.GetEventLogCommand
repeated three times
This was the error:
[PS] C:\batch\diskspace2>.\incw
Get-EventLog : No matches found
At C:\batch\diskspace2\incwhi
+ $logs = Get-EventLog <<<< application -computername $_ -After (get-date)
.Adddays(-7) -InstanceId 1221 | Sort TimeGenerated |
+ CategoryInfo : ObjectNotFound: (:) [Get-EventLog], ArgumentExce
ption
+ FullyQualifiedErrorId : GetEventLogNoEntriesFound,
ommands.GetEventLogCommand
repeated three times
Change line 21 to..
$logs = Get-EventLog application -computername $_ -After (get-date).Adddays(-7) | ? {$_.Eventid -eq 1221} | Sort TimeGenerated |
ASKER
No error this time, took a long while sitting at the prompt (20 minutes) then sent me a blank email.
Sorry
Sorry
I will test In my lab when I get a chance and let you know..
ASKER
thanks
BTB.. Can you try to increase the threshold to 100 and run the script?
ASKER
Hi,
That does produce results, but it seems to be not seeing it a mountpoint and then reporting the same results for whitepsace, for each store:
Systemname label Capacity(GB) FreeSpace(GB) Free(%) Database WhiteSpace(MB)
server1 Data Anchor 0.49 0.46 94 exch1\SG14\DB1 84414
server1 Data Anchor 0.49 0.46 94 exch1\SG10\DB1 84414
server1 Data Anchor 0.49 0.46 94 exch1\SG4\DB1 84414
That does produce results, but it seems to be not seeing it a mountpoint and then reporting the same results for whitepsace, for each store:
Systemname label Capacity(GB) FreeSpace(GB) Free(%) Database WhiteSpace(MB)
server1 Data Anchor 0.49 0.46 94 exch1\SG14\DB1 84414
server1 Data Anchor 0.49 0.46 94 exch1\SG10\DB1 84414
server1 Data Anchor 0.49 0.46 94 exch1\SG4\DB1 84414
I am traveling.. I will test it and let you know as soon as I can... sorry for the delay..
ASKER
no problem
I am back.. :-)
Can you run the following command and post the result?
Can you run the following command and post the result?
Get-MailboxDatabase -Server ServerNAme | Select * -First 1
I addition to above request, I have done some modification, Please test this code and post the result..
[decimal]$threshold = 100
$ExchangeServers = ("server1","server2","server3")
function Get-DBMountPoints([string] $FilePath, [string] $Server)
{
$TotalGB = @{N="Capacity(GB)";E={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{N="FreeSpace(GB)";E={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{N="Free(%)";E={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
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)
$volume | select Systemname, label, $TotalGB, $FreeGB, $FreePerc
}
$DBInfo = $ExchangeServers | % {
$logs = Get-EventLog application -computername $_ -After (get-date).Adddays(-7) | ? {$_.Eventid -eq 1221} | Sort TimeGenerated |
Select TimeGenerated,@{N="Database";E={$_.ReplacementStrings[1]}},@{N="FreeMB";E={$_.ReplacementStrings[0]}}
Foreach ($DB in Get-MailboxDatabase -Server $_){
New-Object PSObject -Property @{
Server = $DB.Server
Database = "$DB"
"WhiteSpace(MB)" = ($logs | ?{$_.Database -match "$DB"} | Sort TimeGenerated -Descending | Select -First 1).FreeMB
}
}
} | Select Server,Database,"WhiteSpace(MB)"
$Body = $DBInfo | % {
$WhiteSpace = $_."WhiteSpace(MB)"
$Database = $_.Database
$DBPath = (Get-MailboxDatabase $Database).EdbFilePath.Pathname -Split "\\"
$DBPath = ($DBPath[0..($DBPath.length - 2)] -join "\")+"\"
Get-DBMountPoints $DBPath $_.Server | Select *,@{N="Database";E={$Database}},@{N="WhiteSpace(MB)";E={$WhiteSpace}}
} | Select Systemname, label, "Capacity(GB)", "FreeSpace(GB)", "Free(%)",Database,"WhiteSpace(MB)" |
?{$_."Free(%)" -lt $threshold} | ConvertTo-Html | Out-String
$messageParameters = @{
Subject = "Exchange DiskSpace Report " + (Get-Date -Format g)
body = $Body
From = "exchangereports@company.com"
To = "myself@company.com"
SmtpServer = "smtp.com"
BodyAsHtml = $true
}
Send-MailMessage @messageParameters
ASKER
Hi,
The last code produced a report with a heading for Whitespcompany but no data underneath, rest of the report was fine.
This command Get-MailboxDatabase -Server ServerNAme | Select * -First 1 produced:
The last code produced a report with a heading for Whitespcompany but no data underneath, rest of the report was fine.
This command Get-MailboxDatabase -Server ServerNAme | Select * -First 1 produced:
[PS] C:\batch\diskspcompany2>Get-MailboxDatabase -Server serverxm301 | Select * -Fir
st 1
JournalRecipient :
MailboxRetention : 3650.00:00:00
OfflineAddressBook : \GDC OAB
OriginalDatabase :
PublicFolderDatabase : serverXP101\PFSG01\PFDB01
ProhibitSendReceiveQuota : unlimited
Recovery : False
ProhibitSendQuota : unlimited
IndexEnabled : True
AdministrativeGroup : Exchange Administrative Group (FYDIBOHF23SPDLT
)
AllowFileRestore : False
BackupInProgress :
CopyEdbFilePath :
DatabaseCreated : True
Description :
EdbFilePath : F:\Exchsrvr\MDBDATA\serverXM301\SG10\DB10.edb
ExchangeLegacyDN : /o=company/ou=Exchange Administrative Group (FYDIB
OHF23SPDLT)/cn=Configuration/cn=Servers/cn=UK7
0PEXM301/cn=Microsoft Private MDB
HasLocalCopy : False
DeletedItemRetention : 45.00:00:00
SnapshotLastFullBackup :
SnapshotLastIncrementalBackup :
SnapshotLastDifferentialBackup :
SnapshotLastCopyBackup :
LastFullBackup :
LastIncrementalBackup :
LastDifferentialBackup :
LastCopyBackup :
MaintenanceSchedule : {Sun.01:00-Sun.05:00, Mon.01:00-Mon.05:00, Tue
.01:00-Tue.05:00, Wed.01:00-Wed.05:00, Thu.01:
00-Thu.05:00, Fri.01:00-Fri.05:00, Sat.01:00-S
at.05:00}
MountAtStartup : True
Mounted :
Organization : company
QuotaNotificationSchedule : {Sun.01:00-Sun.01:15, Mon.01:00-Mon.01:15, Tue
.01:00-Tue.01:15, Wed.01:00-Wed.01:15, Thu.01:
00-Thu.01:15, Fri.01:00-Fri.01:15, Sat.01:00-S
at.01:15}
RetainDeletedItemsUntilBackup : True
Server : serverXM301
ServerName : serverXM301
StorageGroup : serverXM301\SG10
StorageGroupName : SG10
IssueWarningQuota : unlimited
EventHistoryRetentionPeriod : 7.00:00:00
Name : DB10
AdminDisplayName : DB10
ExchangeVersion : 0.1 (8.0.535.0)
DistinguishedName : CN=DB10,CN=SG10,CN=InformationStore,CN=serverX
M301,CN=Servers,CN=Exchange Administrative Gro
up (FYDIBOHF23SPDLT),CN=Administrative Groups,
CN=company,CN=Microsoft Exchange,CN=Services,CN=Co
nfiguration,DC=company,DC=local
Identity : serverXM301\SG10\DB10
Guid : c5926056-6a06-4687-b0fa-27370dc24157
ObjectCategory : company.local/Configuration/Schema/ms-Exch-Private
-MDB
ObjectClass : {top, msExchMDB, msExchPrivateMDB}
WhenChanged : 25/10/2012 11:56:53
WhenCreated : 09/09/2011 10:11:37
OriginatingServer : serverpadc202.companyins.com
IsValid : True
The last code produced a report with a heading for Whitespcompany but no data underneath, rest of the report was fine.I am not clear about what you mean by above statement, Could please clarify or post the screenshot of report?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Try this..
[decimal]$threshold = 100
$ExchangeServers = ("server1","server2","server3")
function Get-DBMountPoints([string] $FilePath, [string] $Server)
{
$TotalGB = @{N="Capacity(GB)";E={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{N="FreeSpace(GB)";E={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{N="Free(%)";E={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
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)
$volume | select Systemname, label, $TotalGB, $FreeGB, $FreePerc
}
$DBInfo = $ExchangeServers | % {
$logs = Get-EventLog application -computername $_ -After (get-date).Adddays(-14) | ? {$_.Eventid -eq 1221} | Sort TimeGenerated |
Select TimeGenerated,@{N="Database";E={$_.ReplacementStrings[1]}},@{N="FreeMB";E={$_.ReplacementStrings[0]}}
Foreach ($DB in Get-MailboxDatabase -Server $_){
$Database = "$($Db.StorageGroupName)\$($DB.Name)"
New-Object PSObject -Property @{
Server = $DB.Server
Database = "$DB"
"WhiteSpace(MB)" = ($logs | ?{$_.Database -eq $Database} | Sort TimeGenerated -Descending | Select -First 1).FreeMB
}
}
} | Select Server,Database,"WhiteSpace(MB)"
$Body = $DBInfo | % {
$WhiteSpace = $_."WhiteSpace(MB)"
$Database = $_.Database
$DBPath = (Get-MailboxDatabase $Database).EdbFilePath.Pathname -Split "\\"
$DBPath = ($DBPath[0..($DBPath.length - 2)] -join "\")+"\"
Get-DBMountPoints $DBPath $_.Server | Select *,@{N="Database";E={$Database}},@{N="WhiteSpace(MB)";E={$WhiteSpace}} |
Select Systemname, label, "Capacity(GB)", "FreeSpace(GB)", "Free(%)",Database,"WhiteSpace(MB)" |
?{$_."Free(%)" -lt $threshold} | ConvertTo-Html | Out-String
}
$messageParameters = @{
Subject = "Exchange DiskSpace Report " + (Get-Date -Format g)
body = $Body
From = "exchangereports@company.com"
To = "myself@company.com"
SmtpServer = "smtp.com"
BodyAsHtml = $true
}
Send-MailMessage @messageParameters
Change line 47 to..
body = $Body | Out-String
body = $Body | Out-String
ASKER
You are welcome!.. I will check on the formatting when I get time and let you know what I get..
Try..
[decimal]$threshold = 100
$ExchangeServers = ("server1","server2","server3")
function Get-DBMountPoints([string] $FilePath, [string] $Server)
{
$TotalGB = @{N="Capacity(GB)";E={[math]::round(($_.Capacity/ 1073741824),2)}}
$FreeGB = @{N="FreeSpace(GB)";E={[math]::round(($_.FreeSpace / 1073741824),2)}}
$FreePerc = @{N="Free(%)";E={[math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0)}}
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)
$volume | select Systemname, label, $TotalGB, $FreeGB, $FreePerc
}
$DBInfo = $ExchangeServers | % {
$logs = Get-EventLog application -computername $_ -After (get-date).Adddays(-14) | ? {$_.Eventid -eq 1221} | Sort TimeGenerated |
Select TimeGenerated,@{N="Database";E={$_.ReplacementStrings[1]}},@{N="FreeMB";E={$_.ReplacementStrings[0]}}
Foreach ($DB in Get-MailboxDatabase -Server $_){
$Database = "$($Db.StorageGroupName)\$($DB.Name)"
New-Object PSObject -Property @{
Server = $DB.Server
Database = "$DB"
"WhiteSpace(MB)" = ($logs | ?{$_.Database -eq $Database} | Sort TimeGenerated -Descending | Select -First 1).FreeMB
}
}
} | Select Server,Database,"WhiteSpace(MB)"
$Dat = $DBInfo | % {
$WhiteSpace = $_."WhiteSpace(MB)"
$Database = $_.Database
$DBPath = (Get-MailboxDatabase $Database).EdbFilePath.Pathname -Split "\\"
$DBPath = ($DBPath[0..($DBPath.length - 2)] -join "\")+"\"
Get-DBMountPoints $DBPath $_.Server | Select *,@{N="Database";E={$Database}},@{N="WhiteSpace(MB)";E={$WhiteSpace}} |
Select Systemname, label, "Capacity(GB)", "FreeSpace(GB)", "Free(%)",Database,"WhiteSpace(MB)" |
?{$_."Free(%)" -lt $threshold}
}
$Body = $Dat | Select Systemname -Unique | % {
$Systemname = $_
$Dat | ? {$_.Systemname -eq $Systemname} | ConvertTo-Html | Out-String
}
$messageParameters = @{
Subject = "Exchange DiskSpace Report " + (Get-Date -Format g)
body = $Body | Out-String
From = "exchangereports@company.com"
To = "myself@company.com"
SmtpServer = "smtp.com"
BodyAsHtml = $true
}
Send-MailMessage @messageParameters