Share via


Powershell: Get Exchange Server Disk Space info via Email Notification.

Microsoft Exchange Server is one of the most important assets in any organization and getting the right information about the Exchange Server in right time is also one of the most important aspect in Exchange administrator life. Here we will walk through the steps involved in setting update notification on daily basis in Exchange administrator inbox to have a clear picture of his Exchange Servers Disk Space, so that admin can do the necessary action to avoid no disk space in Exchange environment due to logs or any other update etc.

Steps

We need to create two files and keep them somewhere in your Exchange drives my docs etc where you have full permission to run these file in-case if you have used delegated account for Exchange installation. File names with extension are as below:-

  • ExchangeDrivesSpace.bat
  • ExchangeDrivesSpace.PS1

Creating .bat File

Open the ExchangeDrivesSpace.bat file and paste the following path which can vary to your environment.

PowerShell.exe -PSConsoleFile "D:\Program Files\Microsoft\Exchange Server\V15\Bin\ExShell.psc1" -Command ". 'C:\Program Files\Update Services\Exchange Bats\Exchange Bats\ExchangeDrivesSpace.PS1'"

 

We can point to this PowerShell.exe where your Exchange is installed. In this case its installed in D:\ so its using that path, than the path of your .PS1 script where your place it.

Creating .PS1 Script

We will open the ExchangeDrivesSapce.PS1 script in any editor and fill the following information.

$messageParameters = @{
 Subject = "Exchange 2013 Disk Space Report - $((Get-Date).ToShortDateString())"
 Body =  Get-ExchangeServer |
 ForEach-Object { Get-WmiObject -computer $_ Win32_LogicalDisk} |
 Where-Object {$_.DriveType -eq 3} |
 Select-Object SystemName, DeviceID, VolumeName, @{Name="Size(GB)";expression={[math]::round(($_.Size / 1073741824))}}, @{Name="Free(GB)";expression={[math]::round(($_.FreeSpace / 1073741824))}}, @{Name="Free(%)";expression={[math]::round(((($_.FreeSpace / 1073741824)/($_.Size / 1073741824)) * 100),0)}} |
 Sort-Object SystemName, DeviceID |
  ConvertTo-Html |
  Out-String
 From = "ExchangeDrivesSpace@mstechguru.ae"
 To = "administrator@mstechguru.ae"
 SmtpServer = "smtp.mstechguru.ae"
}
Send-MailMessage @messageParameters -BodyAsHtml

In the Script you can change Subject value, From Value, To Value and SmtpServer value as per your environment. In From value we can put any dummy email ID which will later appear in Email from option. So no need to put any valid email address in From. In To option we have to put some valid email address for Exchange Administrator who will receive email on daily basis and will keep an eye on increasing disk size.

At this point we have created both files and keep them in C:\ drive somewhere. Now we will create a Schedule Task to run this .bat file on daily basis  at particular time like when administrator takes coffee or tea at morning he/she can schedule this at that time to have a view to his inbox for Exchange Disk status.

Scheduling a Task in Exchange

We will schedule a task in Exchange Server to run the .bat file we created in above steps.

Open the Task Scheduler and click Create Basic Task

Click Next, select Daily and click Next

Click Next, select the Date and time as per your time zone and click Next

Select Start a Program and click Next

Click Next

You can select the path of your .bat file where you place it, in this example the path is as below.

"C:\Program Files\Update Services\Exchange Bats\Exchange Bats\ExchangeDrivesSpace.bat"

Click Next

Click check box. Open the Properties dialog and click Finish

We can have a view of the schedule timings and date, etc. and click OK to finish the task.

Results in Email

Following are the results administrator will receive in his email each day when the schedule will run on a configured date & time.

In this example Exchange application is installed on a separate drive which is showing as ExchangeApp Disk.