Disk Space Checker

One method my company deploys our software is in a dedicated hosted environment. In this situation, we partner with a data center that provides hardware, we install the software and the client doesn’t get access to the hardware directly. This normally works well, unless they tend to have a-lot of activity which could cause the disk to fill prematurely. (Tons of side conversations could be had here about proper sizing, alternative storage methods, etc, but that’s for another day)

Not wanting to go into each system daily and check the available space, I whipped up some Powershell to do the work for me.

A few features I put in here:

  1. Emailed Report
  2. No Credentials Easily Accessible
  3. Only Send if below threshold

Setup

First we import our Net.Mail name space and setup a few user configurable variables.

Basic Checks

In this section, we get the path to the script itself, and look in that same directory for the Credentails and Servers files. If the credentials file does not exists, it will prompt you for the details, which it will then encrypt and save.

Extract the Secrets

This section is where we decrypt the credentials for our email server, as well as read the names of the servers from the $Server file.

Build the Email

Here we have some predefined HTML and CSS, which you could easily save to another file, but for me it made sense to just have it as one scrit.

Send it Or Not?

Notice in this snippet, the conditional statement uses Regex to search our $HTMLMessage for any

. If we see that tag, we know we have data and we can send our email using the standard Net.Mail.SmtpClient using the credentials stored in our credentials file we decrypted above.