SCOM 2007 R2 Rule or Monitor - Powershell script to check if a file exists

javad 1 Reputation point
2020-12-04T15:43:20.687+00:00

Hi, Does anyone know of a Powershell script I can use in a SCOM Rule/Monitor to check if 2 files exist, with a part filename and wildcard? Kind Regards

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,474 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,511 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AlexZhu-MSFT 5,871 Reputation points Microsoft Vendor
    2020-12-08T01:46:31.5+00:00

    Hi,

    It seems we can use the following PS script to achieve our goal.

    $api = New-Object -comObject "MOM.ScriptAPI"    
    $PropertyBag = $api.CreatePropertyBag()  
      
    $file_count = (get-item c:\temp\result*.csv).count  
      
    $PropertyBag.AddValue("FileCount",$file_count)  
    $PropertyBag  
    

    create a unit monitor based on powershell script
    MP download link:
    https://gallery.technet.microsoft.com/Sample-Management-Pack-17b76379

    46062-scom-ps-script-based-monitor-01.png

    name the monitor, add target and enter the powershell script

    46023-scom-ps-script-based-monitor-03.png

    after that, add the criteria

    The criteria we can use:
    Property[@DeezNutz ="FileCount"]

    46024-scom-ps-script-based-monitor-04.png

    Hope the above information helps.

    Alex Zhu


    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.