This article provides a PowerShell script that gathers disk usage and then sends the report. I 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.

Email report showing disk usage

Email report showing disk usage

Preparing SCOM ^

By default, only VBScript can create diagnostic and recovery tasks. Download and install a free, open-source PowerShell community management pack on GitHub to use PowerShell. You likely have already imported management packs for Windows Server operating systems.

PowerShell script ^

The PowerShell script below gathers disk usage. Download the script 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

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

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

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

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

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

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

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 adminteam@contoso.msft. 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

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

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

Initiate task creation by clicking Create

Repeat the steps for the Critical health state.

Screen after repeating 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

Outlook showing disk usage report

Read 4sysops without ads by becoming a member!

Your question was not answered? Ask in the forum!

1+

Users who have LIKED this post:

  • avatar
Share
7 Comments
  1. Emily 1 year ago

    Thank you for this wonderful tool.  I was wondering the best way to scope this to only a certain group of servers.  I have 2 different monitors set up.  One for our Server group, and we get notified on all servers.  I have another monitor set up for another group and they only want to be notified on certain servers.

    I have tried disabling the monitor by default and then enabling it only for that group of servers, but I am getting this error:

    Note: The following information was gathered when the operation was attempted. The information may appear cryptic but provides context for the error. The application will continue to run.

    : Database error. MPInfra_p_ManagementPackInstall failed with exception:
    Failed to validate item: Alias46bfc1e52d1c4f779d1cfdbae45c3117OverrideForDiagnosticMomUIGenaratedDiagnostic6d9af75d83184e4f9672592b78436789ForContextUINameSpace67f813fc09bb4862bbfe98ed5021c116Group

    What is the best way to do what I am wanting to do?

    Thank you for your reply.

    0

  2. Author

    Hi Emily,

    I think keeping the recovery disabled by default and only enabling it for groups of servers is already the right approach.

    In terms of the error message I am a bit puzzled. I haven't meet it so far.

    Could you describe the steps you've done? Like 1. 2. 3. ?
    Have you tried it a second time?
    Are there other alerts below the Operations Manager folder?

    Ruben

    0

  3. Emily 1 year ago

    Here are my steps:

    1. I created the script as you described and chose not to run by default (I am only focused on the one marked No):
    2. I then go to overrides, select the diagnostic task and choose override for a group. I select the group I have made and click OK
    3. I then choose to enable the rule and click OK

    Then the error pops up

    I have tried it numerous times with the same results.

    I am not sure what you are asking about other alerts below the Operations Manager folder.

    Thank you for your time.

    I tried replying this to the email I was sent as well, but not sure if it went through or not.

    0

  4. Author

    Hi Emily,

    whenever I meet errors mentioning something about "Database xyz" then it was because either the OpsMgr DB or the OpsMgr DW was running out of disk space.
    Could you please check if both databases have enough free space?

    In the SCOM console, please also check in Monitoring section the "Operations Manager" folder. Perhaps there are some other interesting messages in the "Active Alerts" views.

    If I understand you right, you unchecked "Run diagnostic automatically" in the step which is title 'Name and describe the diagnostic task'? If so, you could try to keep it enabled and in the dropdown below where you select the target, you can choose a group of servers you like to have it enabled.- You would need to create a dynamic group first of cause.

    ... or, if all is not working just keep it as described above. If someone doesn't like those e-mails they can create a filter-rule to move them directly into the recycle bin 😉

    0

  5. Emily 1 year ago

    I really appreciate your help.  I tried to keep it enabled and then select a target, but the box is blank and will not search for the groups I have created.

    I also looked at the database and it has plenty of space and there aren't any strange errors in the ops man alerts.

    I think I will just leave it as is, and they can ignore the ones that aren't important to them.

    Thank you again for your help.

    0

  6. Author

    Thanks for the feedback, Emily. 🙂

    0

  7. Jakob 6 months ago

    Hi, 

     

    Just discovered this awesome report! I configured it according to the guide but Im not receiving any emails and Im not sure that the diagnostic task even fires. Do you have any ideas?

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account