Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

This script should be customized before running in your environment. 

All Exchange servers which hold a "Mailbox" role will be queried.

The below snippet shows the disks that data is gathered for. For our environment, the mounted LUNs are either labeled with LUN01, LUN02, etc. or have a name of LUN01, etc..

Get-WmiObject -ComputerName $server win32_volume -Filter "DriveType='3'" | Where-Object {$_.Label -like "LUN*" -OR $ -like "*LUN*"}

This is currently being run on a weekly basis via Task Scheduler and send email out via SMTP and saves a local HTML report.

Script can be run from the shell and output will be displayed.

   Get-ExchangeDiskspace.ps1 - Gathers LUN Diskspace from each mailbox server 
   Queries for all Exchange mailbox servers - parses disks to locate LUNs and gathers stats. Exports to report and sends email. 
   .\Get-ExchangeDiskspace.ps1 -ReportMode -SendEmail 
        Checks all servers in the organization, outputs the results to an HTML report and 
        emails the HTML report to the address configured in the script. 
.PARAMETER ReportMode 
    Set to $true to generate a HTML report. A default file name is used if none is specified. 
    Sends the HTML report via email using the SMTP configuration within the script. 
    Written by Jeremy Corbello 
    V1.0 - 6/7/17 
    V1.01 - 6/26/17 - Added removal of existing backup report before creating new backup. 
param (   
        [Parameter( Mandatory=$false)] 
        [Parameter( Mandatory=$false)] 
#Add Exchange snapin if not already loaded in the PowerShell session 
if (Test-Path $env:ExchangeInstallPath\bin\RemoteExchange.ps1) 
    if (-not (Get-PSSession).ConfigurationName -eq "Microsoft.Exchange") { 
        . $env:ExchangeInstallPath\bin\RemoteExchange.ps1 
        Connect-ExchangeServer -auto -AllowClobber 
        Write-Host "Established Remote Exchange Session" 
    } else { 
        Write-Host "Exchange Session Already Established" 
    Write-Warning "Exchange Server management tools are not installed on this computer." 
#Declaring output variables 
$now = Get-Date 
$date = $now.ToShortDateString()     
$titleDate = get-date -uformat "%m-%d-%Y - %A" 
$outPath = "C:\scripts\logs\Exchange_DiskSpace.htm" 
$backupPath = "C:\scripts\logs\Exchange_DiskSpace_Backup.htm" 
$reportemailsubject = "Exchange Diskspace Report - $date" 
#SMTP Settings 
$smtpsettings = @{ 
    To =  "This email address is being protected from spambots. You need JavaScript enabled to view it." 
    From = "This email address is being protected from spambots. You need JavaScript enabled to view it." 
    Subject = "$reportemailsubject" 
    SmtpServer = "" 
#Backup of Previous Log file, Removal of last backup 
if (Test-Path $outPath) { 
    if (Test-Path $backupPath) { 
        Remove-Item -Path $backupPath -Force 
    Move-Item -Path $outPath -Destination $backupPath -Force  
#Gathering Data 
$exchangeServers = Get-ExchangeServer | Where-Object {$_.ServerRole -contains "Mailbox"} | sort name 
$LUNSize = @{} 
foreach ($server in $exchangeServers) { 
    $LUNSize["$($"] = @{} 
    $LUNSize.$($ = Get-WmiObject -ComputerName $server win32_volume -Filter "DriveType='3'" | Where-Object {$_.Label -like "LUN*" -OR $ -like "*LUN*"} | foreach { 
        New-Object PSObject -Property @{ 
            LUN = $_.Label 
            FreeSpace_TB = ([MATH]::Round($_.FreeSpace / 1TB,2)) 
            TotalSize_TB = ([MATH]::Round($_.Capacity / 1TB,2)) 
            Name = $server.Name 
            PercentFree = ([MATH]::Round(($_.FreeSpace/$_.Capacity)*100,2)) 
#Writing output to console 
foreach ($server in $exchangeServers) { 
    $LUNSize.$($ | ft -AutoSize | Out-Host 
if ($ReportMode -or $SendEmail) { 
    $header = " 
            <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
            <title>DiskSpace Report</title> 
            <STYLE TYPE='text/css'> 
                table { 
                        border: thin solid #666666; 
                        margin-left: auto;  
                        margin-right: auto; 
            td { 
                font-family: Tahoma; 
                font-size: 13px; 
                border-top: 1px solid #999999; 
                border-right: 1px solid #999999; 
                border-bottom: 1px solid #999999; 
                border-left: 1px solid #999999; 
                padding-top: 0px; 
                padding-right: 2px; 
                padding-bottom: 0px; 
                padding-left: 2px; 
            body { 
                margin-top: 5px; 
                margin-bottom: 10px; 
                margin-left: auto;  
                margin-right: auto; 
                table { 
                border: thin solid #000000; 
            <table width='100%'> 
            <tr bgcolor='#CCCCCC'> 
            <td colspan='7' height='25' align='center'> 
            <font face='tahoma' color='#003399' size='4'><strong>DiskSpace Report for $titledate</strong></font> 
    $htmltail = "</body> 
    if ($ReportMode) { 
        $header | Out-File $outPath 
    foreach ($server in $exchangeServers) { 
        $htmlbody += [PSCustomObject]$LUNSize.$($ | ConvertTo-Html -Fragment -Property Name,LUN,FreeSpace_TB,TotalSize_TB,PercentFree 
        if ($ReportMode) { 
            [PSCustomObject]$LUNSize.$($ | ConvertTo-Html -Fragment -Property Name,LUN,FreeSpace_TB,TotalSize_TB,PercentFree | Out-File $outPath -Append  
            $htmltail | Out-File $outPath -Append 
    $htmlreport = $header + $htmlbody + $htmltail 
    if ($SendEmail) { 
        $htmlreport = $header + $htmlbody + $htmltail 
        Send-MailMessage @smtpsettings -Body $htmlreport -BodyAsHtml -Encoding ([System.Text.Encoding]::UTF8)