Skip to Main Content

Send disk usage reports on ‘disk full’ alerts in SCOM

Ruben Zimmermann
Infrastructure Architect, SIG

We welcome back Ruben Zimmerman today for his latest guest blog! Ruben is an infrastructure specialist, who specializes in Active Directory, public key infrastructure and System Center Operations Manager (SCOM). Ruben has written an article on how to send disk usage reports on 'disk full' alerts in SCOM - we've reposted it below!

Introduction

This article provides a PowerShell script that gathers disk usage and then sends the report. It will also describe the steps to configure a diagnostic task on a 'disk full' alert in SCOM.

It may happen because we sized a disk wrongly, did not expect growth of the WinSxS folder, neglected to stop IIS logging during troubleshooting, or because the developer did not implement a log-cleanup routine in her application. Full disks can have many reasons.

The first step when receiving an alert about a filling disk is to RDP into a server and use tools to analyze the disk consumption. This takes time and reoccurs — an ideal candidate for scripting and automation.

Diagnostic tasks in SCOM can run scripts or commands directly on the affected machine when an alert occurs.

PowerShell Script

The PowerShell script below gathers disk usage. Download the script here and name it Get-LargeDirectoriesAndFiles.ps1.

Create the diagnostic task

In the SCOM console, switch to the Authoring pane and expand Management Pack Objects and Monitors. Limit the search to logical disk. Right click Windows [20XX] Logical Disk Free Space Monitor.

Open the context menu of the Windows 2008 Logical Disk Free Space Monitor

Switch to the Diagnostic and Recovery tab, click Add…, and choose Diagnostic for warning health state.

Specify the alert state that will trigger the task

Chose Run a PowerShell script (Community) and click New… to create a management pack to store the task in.

Select Run a PowerShell script (Community) and click New

Choose a fitting name like Windows.Server.Custom.Tasks and proceed by clicking Next.

Name the new management pack and proceed

As an optional step, you can specify additional information in the Knowledge section. Proceed by clicking Create.

Complete the management pack creation by clicking Create

Back in the Task Wizard, ensure that Run a PowerShell script (Community) is still selected and click Next.

Verify Run a PowerShell script (Community) is selected and proceed

In the General section, specify a task name, such as Disk Full - Troubleshooting Assistance and optionally a description, such as Scans the partition and sends a utilization report to the admin team. Proceed by clicking Next.

Name and describe the diagnostic task

In the Script section, enter a File Name, such as Get-LargeDirectoriesAndFiles.ps1, set the timeout to 5 minutes, and paste the Script into it.

Set the variable $emailTo to specify the recipient of the disk usage report, such as [email protected]. The variable $smtpSrv specifies the name that will send the mail, and set $emailFrom specifies the sender address.

Optionally you can adjust the values for the number of directories ($numberOfTopDirectories) and files ($numberOfTopFiles) to show on the report.

Paste and configure script values

Stay on the current screen and click Parameters. There, select Device Identifier (Windows Logical Hardware Component) from the list.

Specify script parameters

Initiate the task creation by clicking Create. Depending on your environment, this may take a while.

Initiate task creation by clicking Create

Repeat the steps for the Critical health state.

Screen after repeating the steps for the Critical health state

Repeat the procedure for all other Windows Server versions. Otherwise it will only work for Windows Server 2008.

The next time a disk fills up, you'll receive an e-mail like the one below.

Outlook showing disk usage report

Thanks Ruben! If you'd like to read more on this topic, head on over to our Community Answers platform and check out the discussion titled 'Disk Usage Report Task'.

Ruben Zimmermann
Infrastructure Architect, SIG