Health Monitoring 1.jpg

DIY: How to Automatically Monitor Storage Health in Windows Server

Here’s how to automatically monitor storage health using a PowerShell cmdlet.

For more technical explainers on PowerShell, read our PowerShell 101: A Technical Explainer for IT Pros report.

Windows Server includes a PowerShell cmdlet called Get-ClusterPerformanceHistory that gives organizations a way to monitor storage health. The cmdlet returns a wealth of information about a cluster’s storage health, but you can take advantage of this information only if you remember to use cmdlet. However, there is a way to set up PowerShell to automatically run the cmdlet on a scheduled basis. Here’s how to set up automatic storage health monitoring in Windows Server using the Get-ClusterPerformanceHistory cmdlet.

There are three basic tasks you will need to perform to monitor storage health using the Get-ClusterPerformanceHistory cmdlet:

  • Make the script run according to a schedule.
  • Configure the script to check to make sure that reported values fall within the expected range.
  • Send an alert to an administrator if values exceed a predetermined threshold.

So let’s take a look at how you might accomplish these three tasks.

1. Run the script on a schedule.

It’s relatively easy to make a PowerShell script run automatically according to a schedule by using the Windows Task Scheduler.

To do so, open the Task Scheduler, then choose the Create Task option. The Create Task window is divided into several tabs. The General tab lets you assign a name to the task, and you can use the Triggers tab to set up the task schedule. The Actions tab is where you will need to go to tell Windows to run your PowerShell script. Make sure that the Action option is set to Start a Program, and then set powershell.exe as the program name.  You can then use the Add Arguments section to specify the name of the script you want to run. You will need to specify the -File switch followed by the path and filename of the script. You can see an example of this in Figure 1.

Health Monitoring 2.jpg

Figure 1

This is how you configure Windows Task Scheduler to run a PowerShell script.

2. Test the reported values.

Extracting values from the report is a little bit tricky, but it can be done. For the sake of demonstration, let’s pretend that we want to display a message saying that everything is OK if there is more than 25 GB of available space. In real life, we would probably want to call an alerting function if the available space was found to be inadequate, but simply displaying a message will make for a simple demonstration. Here is what the code looks like:

$History = Get-ClusterPerformanceHistory

$Available = $History | Where-Object {$_.MetricID -eq ‘Volume.Size.Available,Cluster=S2DCluster’)

If ($Available.Value -gt 25000000000) {Write-Host ‘Everything is OK’} else {Write-Host ‘The volume is running low on space’}

You can see what this looks like in Figure 2.

Health Monitoring 3.jpg

Figure 2

This is how we can test the reported values against predetermined thresholds.

One thing that you need to know about the block of code that I just showed you is that the Cluster= portion of the Volume.Available statement reflects the name of my own cluster. You will need to substitute your own cluster name.

3. Send an administrative alert.

The last task you need to complete to monitor storage health using the Get-ClusterPerformanceHistory cmdlet is to send an administrative alert. The most common option for this is likely to make PowerShell send an email message. Microsoft provides a PowerShell cmdlet named Send-MailMessage that you can use to accomplish this task. Microsoft recommends against using this cmdlet because it does not guarantee a secure connection to the SMTP server. The command does, however, work.

If you prefer not to use email, another option is to display a popup window. You can accomplish this with two lines of code:

$Popup = New-Object -ComObject Wscript.Shell

$Popup.Popup("This is how you create a popup message")

You can see what the code and the resulting pop-up window look like in Figure 3.

Health Monitoring 4.jpg

Figure 3

This is how you create a popup window using PowerShell.

If you were planning on using this technique in real life, there are two things that you would need to do. First, you would want to replace the static text with a message that reflects the condition that you are reporting on. I advise creating a function that generates the popup. If the script finds a problematic value, it could add a message to a variable and then pass that variable to the function that displays the popup.

The other thing that you should do is to configure the script to establish a remote session. Otherwise, PowerShell will display the popup on whatever machine the script runs on, rather than displaying it on an administrative workstation.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish