SCOM monitor folder size if goes above threshold

bobby33 21 Reputation points
2021-02-09T14:30:10.163+00:00

Trying to figure out how to include an PS script or VB script to throw an alert whenever folder
goes above threshold.

I got this from web adding the file path to the parameter field in ps script monitor
not seems to work

param($FolderPath)
$api = new-object -comObject 'MOM.ScriptAPI'
$bag = $api.CreatePropertyBag()

$Result = "{0:N2}" -f ((Get-ChildItem -path $FolderPath -recurse | Measure-Object -property length -sum ).sum /1GB)
If($Result -gt "3")
{$bag.AddValue('Result','BAD')}
else
{$bag.AddValue('Result','GOOD')}
$bag

Operations Manager
Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,547 questions
0 comments No comments
{count} votes

Accepted answer
  1. AlexZhu-MSFT 6,581 Reputation points Microsoft External Staff
    2021-02-10T03:00:35.353+00:00

    Hi,

    It seems the logic is correct. Since the current method doesn't work, we may considering just passing the result and comparing this in the criteria.

    In the powershell, just pass the result.

    $Result = "{0:N2}" -f ((Get-ChildItem -path $FolderPath -recurse | Measure-Object -property length -sum ).sum /1GB)  
    $bag.AddValue('Result',$Result)  
    $bag  
    

    Here's some screenshots from the lab, for your reference.

    enter the script (if Linux computer, just provide the script path that already created in Linux)
    scom_ps_script_based_monitor_03.PNG
    66133-scom-ps-script-based-monitor-03.png

    configure the criteria (compare the current value with the threshold)
    scom_ps_script_based_monitor_04.PNG
    65970-scom-ps-script-based-monitor-04.png

    map health status
    scom_ps_script_based_monitor_06.PNG
    66059-scom-ps-script-based-monitor-06.png

    enable alerting and write the alert description if necessary
    scom_ps_script_based_monitor_07.PNG
    66060-scom-ps-script-based-monitor-07.png

    Hope the above information helps.

    Alex
    If the response is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. AlexZhu-MSFT 6,581 Reputation points Microsoft External Staff
    2021-03-01T01:12:58.84+00:00

    Hi,

    It seems there is no update for a couple of days. May we know the current status of the problem? Is there any other assistance we can provide?

    Regards,

    Alex
    If the response is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.