locked
Script monitor (file count in folder) does not work RRS feed

  • Question

  • Hi together,

    I am not so familiar with script monitoring in SCOM. I created a script monitor (PowerShell) which checks the number of files in a folder every 30 minutes. If the threshold more than 10, then it should send an alert.

    Unfortunately it does not work. I list the code below. Any idea?

    $ScomAPI = new-object -comObject "MOM.ScriptAPI"
    $PropertyBag = $ScomAPI.CreatePropertyBag()
    $filesCount = (dir $folderName | measure).Count
    
    try {
    	if ($filesCount -le $Threshold){
      	$PropertyBag.AddValue("State","OK")
    	}
    	else{
    	$PropertyBag.AddValue("State","ERROR")
    	}
    }
    
    finally {
    	#Collect for alert or performance collection
    	$PropertyBag.AddValue("FilesCount",$Threshold)
    	
    	#State value for Monitor
    	$PropertyBag.AddValue("State",$State)
    
    	# Send output to SCOM
    	$PropertyBag
    }

    Best regards

    Birdal

    Wednesday, July 22, 2020 7:36 AM

All replies

  • Could you post the full monitor and monitortype code? (the whole xml thing)
    Wednesday, July 22, 2020 8:10 AM
  • Hi Cyraz,

    the monitor code is below:

    <?xml version="1.0"
          encoding="utf-16"?>
    <UnitMonitor ID="UIGeneratedMonitorf9f1caeec4eb456bb3c4ae8cbfc145ba"
        Accessibility="Public"
        Enabled="false"
        Target="MITZSWSUSWindows!MIT.ZS.WSUS.Windows.Class"
        ParentMonitorID="Health!System.Health.AvailabilityState"
        Remotable="true"
        Priority="Normal"
        TypeID="PowerShellMonitoring!Community.PowerShellMonitoring.UnitMonitors.PowerShellTwoState"
        ConfirmDelivery="false">
      <Category>Custom</Category>
      <AlertSettings AlertMessage="UIGeneratedMonitorf9f1caeec4eb456bb3c4ae8cbfc145ba_AlertMessageResourceID">
        <AlertOnState>Warning</AlertOnState>
        <AutoResolve>true</AutoResolve>
        <AlertPriority>Normal</AlertPriority>
        <AlertSeverity>Error</AlertSeverity>
        <AlertParameters>
          <AlertParameter1>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/DNSName$</AlertParameter1>
        </AlertParameters>
      </AlertSettings>
      <OperationalStates>
        <OperationalState ID="UIGeneratedOpStateId134223a96956457182185c7af27bbdd9"
            MonitorTypeStateID="Healthy"
            HealthState="Success" />
        <OperationalState ID="UIGeneratedOpStateIdd7a767a554504bcebf93ae23dcef16ac"
            MonitorTypeStateID="Unhealthy"
            HealthState="Warning" />
      </OperationalStates>
      <Configuration>
        <IntervalSeconds>180</IntervalSeconds>
        <SyncTime />
        <ScriptName>Test.WSUS.FileCount.ps1</ScriptName>
        <ScriptBody>$ScomAPI = new-object -comObject "MOM.ScriptAPI"
    $PropertyBag = $ScomAPI.CreatePropertyBag()
    $filesCount = (dir $folderName | measure).Count
    
    try {
    	if ($filesCount -le $Threshold){
      	$PropertyBag.AddValue("State","OK")
    	}
    	else{
    	$PropertyBag.AddValue("State","ERROR")
    	}
    }
    
    finally {
    	#Collect for alert or performance collection
    	$PropertyBag.AddValue("FilesCount",$Threshold)
    	
    	#State value for Monitor
    	$PropertyBag.AddValue("State",$State)
    
    	# Send output to SCOM
    	$PropertyBag
    }</ScriptBody>
        <Arguments>[int]$Threshold = 10
    $;[string]folderName = "D:\MyFolder"</Arguments>
        <TimeoutSeconds>60</TimeoutSeconds>
        <UnhealthyExpression>
          <SimpleExpression>
            <ValueExpression>
              <XPathQuery>Property[@Name='State']</XPathQuery>
            </ValueExpression>
            <Operator>Equal</Operator>
            <ValueExpression>
              <Value Type="String">ERROR</Value>
            </ValueExpression>
          </SimpleExpression>
        </UnhealthyExpression>
        <HealthyExpression>
          <SimpleExpression>
            <ValueExpression>
              <XPathQuery>Property[@Name='State']</XPathQuery>
            </ValueExpression>
            <Operator>Equal</Operator>
            <ValueExpression>
              <Value Type="String">OK</Value>
            </ValueExpression>
          </SimpleExpression>
        </HealthyExpression>
      </Configuration>
    </UnitMonitor>

    Override (only for a computer object, this monitor is enabled):

    <?xml version="1.0"
          encoding="utf-16"?>
    <MonitorPropertyOverride ID="Aliasbc651ea178144c70b5e884cb48048e29OverrideForMonitorUIGeneratedMonitorf9f1caeec4eb456bb3c4ae8cbfc145baForContextMicrosoftWindowsComputer"
        Context="Windows!Microsoft.Windows.Computer"
        ContextInstance="ac149de7-f7fb-c656-76b3-40a16b0d4659"
        Enforced="false"
        Monitor="UIGeneratedMonitorf9f1caeec4eb456bb3c4ae8cbfc145ba"
        Property="Enabled">
      <Value>true</Value>
    </MonitorPropertyOverride>

    Best regards

    Birdal

    Wednesday, July 22, 2020 10:49 AM
  • Your issue is because you don't initialize the arguments inside the script.

    It needs to start with a param section : 

    param([String]$Arguments)

    And then you need to split the $Arguments variable and assign it to the actual variables you use in the script ($foldername and $threshold).

    Example here : https://community.squaredup.com/answers/question/multiple-parameters-with-powershell-monitors/

    Also your scripts return a property in the propertybag with a name of "filescount" and a value of $threhsold, which is probably not what you intended to do.

    Wednesday, July 22, 2020 11:58 AM
  • Hi Cyraz,

    Sorry, but I don't understand this splitting. In addition, the paramater $Threshold ist integer, not string, but $folderName is string. In your example you write only for parameters with "string". If I see any example how I can split and set arguments for string and int values, can I better imagine what is meant.

    It is to me too abstract.

    Best regards

    Birdal

    Wednesday, July 22, 2020 2:04 PM
  • The easiest way would be to replace this : 

        <Arguments>[int]$Threshold = 10$;[string]folderName = "D:\MyFolder"</Arguments>

    With this : 

        <Arguments>10;D:\MyFolder</Arguments>

    And then add something like this at the very beginning of the script :

    (param $Arguments)
    
    $argumentList = $arguments -split ";"
    
    $Threshold = $argumentList[0]
    $folderName = $argumentList[1]


    • Edited by CyrAz Wednesday, July 22, 2020 5:48 PM
    Wednesday, July 22, 2020 5:48 PM
  • Hi Cyraz,

    mustn't be so actually?

    [int]$Threshold = $argumentList[0]
    [string]$folderName = $argumentList[1]

    If it is not declarated, how can script know that whether these parameters int or string? 

    Is that then so correct?

    (param $Arguments) $argumentList = $arguments -split ";"

    [int]$Threshold = $argumentList[0]

    [string]$folderName = $argumentList[1]

    $ScomAPI = new-object -comObject "MOM.ScriptAPI"

    $PropertyBag = $ScomAPI.CreatePropertyBag() $filesCount = (dir $folderName | measure).Count try { if ($filesCount -le $Threshold){ $PropertyBag.AddValue("State","OK") } else{ $PropertyBag.AddValue("State","ERROR") } } finally { #Collect for alert or performance collection $PropertyBag.AddValue("FilesCount",$Threshold) #State value for Monitor $PropertyBag.AddValue("State",$State) # Send output to SCOM $PropertyBag }

    Best regards

    Birdal

    Thursday, July 23, 2020 11:19 AM
  • Powershell doesn't require an explicit typing of the variables because it is capable of detecting their type depending on the value they get, but it's of course still a best practice to declare their type.

    The "Argument" part of your script looks correct, but  $PropertyBag.AddValue("FilesCount",$Threshold) is still probably wrong.

    And don't forget to modify the <Arguments>...</Arguments> part of your XML as well.

    Thursday, July 23, 2020 11:37 AM
  • Hi Cyraz,

    no, the script did not work.

    Then I changed script as follow. Now alert will be generated, but not correctly. It means: although Folder includes only 9 files and $Threshold=10, it will be an alert generated. 

    # Load the MOMScript API and the PropertBag provider
    $ScomAPI = new-object -comObject "MOM.ScriptAPI"
    $PropertyBag = $ScomAPI.CreatePropertyBag()
    
    # Parameters
    Param ([int]$Threshold, [string]$folderName)
    
    # Main script
    $filesCount = (dir $folderName | measure).Count
    
    #Add the data into the PropertyBag
    $PropertyBag.AddValue("FilesInFolder",$filesCount)
    
    if ($filesCount -le $Threshold){
    	$PropertyBag.AddValue("State","OK")
        }
    else {
    	$PropertyBag.AddValue("State","ERROR")
           }
    
    # Output the PropertyBag data for SCOM consumption:
    $PropertyBag

    Best regards

    Birdal

    Thursday, July 23, 2020 2:51 PM
  • Hi,

    We may try to only return FilesInFolder and judge it in the next steps of the monitor creation.

    For the unhealthy, we can set

    FilesInFolder is greater than 9 as shown in below example.



    the script only returns the FilesInFolder




    The whole script example:

    'get file count
    $api = New-Object -comObject "MOM.ScriptAPI" 
    $PropertyBag = $api.CreatePropertyBag()
    $fc = (Get-ChildItem -path c:\temp -file | Measure-Object).Count
    $PropertyBag.AddValue("FileCount",$fc)
    $PropertyBag


    Hope the above information helps.

    Regards,

    Alex Zhu
    -----------------------------------------------
    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, July 24, 2020 9:02 AM
  • Hi Cyraz,

    no, the script did not work.

    Then I changed script as follow. Now alert will be generated, but not correctly. It means: although Folder includes only 9 files and $Threshold=10, it will be an alert generated. 

    # Load the MOMScript API and the PropertBag provider
    $ScomAPI = new-object -comObject "MOM.ScriptAPI"
    $PropertyBag = $ScomAPI.CreatePropertyBag()
    
    # Parameters
    Param ([int]$Threshold, [string]$folderName)
    
    # Main script
    $filesCount = (dir $folderName | measure).Count
    
    #Add the data into the PropertyBag
    $PropertyBag.AddValue("FilesInFolder",$filesCount)
    
    if ($filesCount -le $Threshold){
    	$PropertyBag.AddValue("State","OK")
        }
    else {
    	$PropertyBag.AddValue("State","ERROR")
           }
    
    # Output the PropertyBag data for SCOM consumption:
    $PropertyBag

    Best regards

    Birdal

    Does the folder also contains subfolders? By default, Get-ChildItem (which is the actual cmdlet that runs when you write "dir") will return child files and folders. So if you have 9 files and a subfolder, the result will be 10 and therefore it is normal that the state is "ERROR".

    If it is indeed the case and you only want to count files, you should write "Get-ChildItem -File" instead of "dir".

    Also all this is more a "powershell" question than a "SCOM" question, you may have more answers on a Powershell forum :)


    • Edited by CyrAz Friday, July 24, 2020 9:42 AM
    Friday, July 24, 2020 9:41 AM
  • Hi Alex,

    I want use two parameters which can be overrided: $Threshold and $folderName.

    Bye

    Birdal

    Friday, July 24, 2020 12:39 PM
  • Hi Cyraz,

    no, the issue does not depend on PowerShell command. The folder does not incluse any subfolder. I tested it many times. I tested also with Get-Childitem -File $folderName. It is the same issue.

    It is really bad that there is no good documentation about Script Monitoring in SCOM!

    Best regards

    Birdal

    Friday, July 24, 2020 12:42 PM
  • Hi,

    I used now a Management Pack from MARTELLO. It works, but it is not a good solution (https://martellotech.com/downloads/mp-scom-files-folders-monitoring)

    The problem is that there is no possibility to override the parameters $folderName and $Threshold in this Management Pack. In addition, you cannot select/override for a given computer object.

    Best regards

    Birdal

    Friday, July 24, 2020 12:49 PM
  • There is no real need for a specific "scripted monitoring documentation" : if the script is properly written, it returns property bags in the workflow and nothing more. And then the workflow works like any other workflow, 

    Which means if you have an issue with scripted monitoring, it usually boils down to the following two options (or a combination of both) : 

    - The script has issues. But that would be purely a powershell problem, not a SCOM problem.

    - The workflow has issues. But in that case, it is not related to "scripted" monitoring : there would be an issue in the workflow whatever its datasource is, so that would be "SCOM authoring documentation" you need (and there is an excellent series of videos about that by Brian Wren).

    Could you show us again the full xml you obtained after you fixed the script for the last time? I suspect the Arguments are written in such a way that doesn't allow them to be passed properly into the script, and therefore the script is not working properly.

    Friday, July 24, 2020 1:28 PM
  • Hi Cyraz,

    that is all MP (test MP) incl. script and override.

    <?xml version="1.0"
          encoding="utf-8"?>
    <ManagementPack ContentReadable="true"
    		SchemaVersion="2.0"
    		OriginalSchemaVersion="1.1"
    		xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    		xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<Manifest>
    		<Identity>
    			<ID>Test.Monitoring.FileCountInFolder</ID>
    			<Version>1.0.0.4</Version>
    		</Identity>
    		<Name>Test.Monitoring.FileCountInFolder</Name>
    		<References>
    			<Reference Alias="Health">
    				<ID>System.Health.Library</ID>
    				<Version>7.0.8438.6</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="System">
    				<ID>System.Library</ID>
    				<Version>7.5.8501.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="NetworkLibrary">
    				<ID>System.NetworkManagement.Library</ID>
    				<Version>7.3.13142.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="NetworkMonitoring">
    				<ID>System.NetworkManagement.Monitoring</ID>
    				<Version>7.3.13142.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="Snmp">
    				<ID>System.Snmp.Library</ID>
    				<Version>7.0.8438.6</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="TestCustomerWindows">
    				<ID>Test.Customer.Windows</ID>
    				<Version>1.0.0.0</Version>
    				<PublicKeyToken>7c56ce53dba63531</PublicKeyToken>
    			</Reference>
    			<Reference Alias="SCInternal">
    				<ID>Microsoft.SystemCenter.Internal</ID>
    				<Version>7.0.8437.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="SC">
    				<ID>Microsoft.SystemCenter.Library</ID>
    				<Version>7.0.8437.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="Windows">
    				<ID>Microsoft.Windows.Library</ID>
    				<Version>7.5.8501.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    			<Reference Alias="Performance">
    				<ID>System.Performance.Library</ID>
    				<Version>7.0.8437.0</Version>
    				<PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
    			</Reference>
    		</References>
    	</Manifest>
    	<TypeDefinitions>
    		<ModuleTypes>
    			<DataSourceModuleType ID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType"
    					Accessibility="Internal"
    					Batching="false">
    				<Configuration>
    					<xsd:element type="xsd:integer"
    							name="TimeoutSeconds"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:integer"
    							name="IntervalSeconds"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:integer"
    							name="Threshold"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:string"
    							name="folderName"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    				</Configuration>
    				<OverrideableParameters>
    					<OverrideableParameter ID="TimeoutSeconds"
    							Selector="$Config/TimeoutSeconds$"
    							ParameterType="int" />
    					<OverrideableParameter ID="IntervalSeconds"
    							Selector="$Config/IntervalSeconds$"
    							ParameterType="int" />
    					<OverrideableParameter ID="Threshold"
    							Selector="$Config/Threshold$"
    							ParameterType="int" />
    					<OverrideableParameter ID="folderName"
    							Selector="$Config/folderName$"
    							ParameterType="string" />
    				</OverrideableParameters>
    				<ModuleImplementation Isolation="Any">
    					<Composite>
    						<MemberModules>
    							<DataSource ID="Scheduler"
    									TypeID="System!System.Scheduler">
    								<Scheduler>
    									<SimpleReccuringSchedule>
    										<Interval Unit="Seconds">$Config/IntervalSeconds$</Interval>
    									</SimpleReccuringSchedule>
    									<ExcludeDates />
    								</Scheduler>
    							</DataSource>
    							<ProbeAction ID="Probe"
    									TypeID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType">
    								<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
    								<Threshold>$Config/Threshold$</Threshold>
    								<folderName>$Config/folderName$</folderName>
    							</ProbeAction>
    						</MemberModules>
    						<Composition>
    							<Node ID="Probe">
    								<Node ID="Scheduler" />
    							</Node>
    						</Composition>
    					</Composite>
    				</ModuleImplementation>
    				<OutputType>System!System.PropertyBagData</OutputType>
    			</DataSourceModuleType>
    			<ProbeActionModuleType ID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType"
    					Accessibility="Internal"
    					Batching="false"
    					PassThrough="false">
    				<Configuration>
    					<xsd:element type="xsd:integer"
    							name="TimeoutSeconds"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:integer"
    							name="Threshold"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:string"
    							name="folderName"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    				</Configuration>
    				<OverrideableParameters>
    					<OverrideableParameter ID="TimeoutSeconds"
    							Selector="$Config/TimeoutSeconds$"
    							ParameterType="int" />
    					<OverrideableParameter ID="Threshold"
    							Selector="$Config/Threshold$"
    							ParameterType="int" />
    					<OverrideableParameter ID="folderName"
    							Selector="$Config/folderName$"
    							ParameterType="string" />
    				</OverrideableParameters>
    				<ModuleImplementation Isolation="Any">
    					<Composite>
    						<MemberModules>
    							<ProbeAction ID="Probe"
    									TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe">
    								<ScriptName>Test.Monitoring.ScriptMonitor.FilesCountInFolder.ps1</ScriptName>
    								<ScriptBody># Load the MOMScript API and the PropertBag provider
    $ScomAPI = new-object -comObject "MOM.ScriptAPI"
    $PropertyBag = $ScomAPI.CreatePropertyBag()
    
    # Parameters
    Param ([int]$Threshold, [string]$folderName)
    
    # Main script
    $filesCount = (dir $folderName | measure).Count
    
    #Add the data into the PropertyBag
    $PropertyBag.AddValue("FilesInFolder",$filesCount)
    
    if ($filesCount -le $Threshold){
    	$PropertyBag.AddValue("State","SUCCESS")
        }
    else {
    	$PropertyBag.AddValue("State","ERROR")
           }
    
    # Output the PropertyBag data for SCOM consumption:
    $PropertyBag
    </ScriptBody>
    								<Parameters>
    									<Parameter>
    										<Name>Threshold</Name>
    										<Value>$Config/Threshold$</Value>
    									</Parameter>
    									<Parameter>
    										<Name>folderName</Name>
    										<Value>$Config/folderName$</Value>
    									</Parameter>
    								</Parameters>
    								<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
    								<StrictErrorHandling>false</StrictErrorHandling>
    							</ProbeAction>
    						</MemberModules>
    						<Composition>
    							<Node ID="Probe" />
    						</Composition>
    					</Composite>
    				</ModuleImplementation>
    				<OutputType>System!System.PropertyBagData</OutputType>
    				<TriggerOnly>true</TriggerOnly>
    			</ProbeActionModuleType>
    		</ModuleTypes>
    		<MonitorTypes>
    			<UnitMonitorType ID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType"
    					Accessibility="Internal">
    				<MonitorTypeStates>
    					<MonitorTypeState ID="UnderWarning"
    							NoDetection="false" />
    					<MonitorTypeState ID="OverError"
    							NoDetection="false" />
    				</MonitorTypeStates>
    				<Configuration>
    					<xsd:element type="xsd:integer"
    							name="TimeoutSeconds"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:integer"
    							name="IntervalSeconds"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:integer"
    							name="Threshold"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    					<xsd:element type="xsd:string"
    							name="folderName"
    							xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
    				</Configuration>
    				<OverrideableParameters>
    					<OverrideableParameter ID="TimeoutSeconds"
    							Selector="$Config/TimeoutSeconds$"
    							ParameterType="int" />
    					<OverrideableParameter ID="IntervalSeconds"
    							Selector="$Config/IntervalSeconds$"
    							ParameterType="int" />
    					<OverrideableParameter ID="Threshold"
    							Selector="$Config/Threshold$"
    							ParameterType="int" />
    					<OverrideableParameter ID="folderName"
    							Selector="$Config/folderName$"
    							ParameterType="string" />
    				</OverrideableParameters>
    				<MonitorImplementation>
    					<MemberModules>
    						<DataSource ID="DataSource"
    								TypeID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType">
    							<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
    							<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
    							<Threshold>$Config/Threshold$</Threshold>
    							<folderName>$Config/folderName$</folderName>
    						</DataSource>
    						<ProbeAction ID="Probe"
    								TypeID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType">
    							<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
    							<Threshold>$Config/Threshold$</Threshold>
    							<folderName>$Config/folderName$</folderName>
    						</ProbeAction>
    						<ConditionDetection ID="UnderWarningFilter"
    								TypeID="System!System.ExpressionFilter">
    							<Expression>
    								<SimpleExpression>
    									<ValueExpression>
    										<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
    									</ValueExpression>
    									<Operator>Equal</Operator>
    									<ValueExpression>
    										<Value Type="String">SUCCESS</Value>
    									</ValueExpression>
    								</SimpleExpression>
    							</Expression>
    						</ConditionDetection>
    						<ConditionDetection ID="OverErrorFilter"
    								TypeID="System!System.ExpressionFilter">
    							<Expression>
    								<SimpleExpression>
    									<ValueExpression>
    										<XPathQuery Type="String">Property[@Name='State']</XPathQuery>
    									</ValueExpression>
    									<Operator>Equal</Operator>
    									<ValueExpression>
    										<Value Type="String">ERROR</Value>
    									</ValueExpression>
    								</SimpleExpression>
    							</Expression>
    						</ConditionDetection>
    					</MemberModules>
    					<RegularDetections>
    						<RegularDetection MonitorTypeStateID="UnderWarning">
    							<Node ID="UnderWarningFilter">
    								<Node ID="DataSource" />
    							</Node>
    						</RegularDetection>
    						<RegularDetection MonitorTypeStateID="OverError">
    							<Node ID="OverErrorFilter">
    								<Node ID="DataSource" />
    							</Node>
    						</RegularDetection>
    					</RegularDetections>
    					<OnDemandDetections>
    						<OnDemandDetection MonitorTypeStateID="UnderWarning">
    							<Node ID="UnderWarningFilter">
    								<Node ID="DataSource" />
    							</Node>
    						</OnDemandDetection>
    						<OnDemandDetection MonitorTypeStateID="OverError">
    							<Node ID="OverErrorFilter">
    								<Node ID="DataSource" />
    							</Node>
    						</OnDemandDetection>
    					</OnDemandDetections>
    				</MonitorImplementation>
    			</UnitMonitorType>
    		</MonitorTypes>
    	</TypeDefinitions>
    	<Monitoring>
    		<Monitors>
    			<UnitMonitor ID="Test.Monitoring.ScriptMonitor.FilesCountInFolder"
    					Comment="&lt;Silect&gt;&lt;Op&gt;Created&lt;/Op&gt;&lt;User&gt;myDomain\myAccount&lt;/User&gt;&lt;Previous/&gt;&lt;LastModified&gt;2020-07-27 13:55:14Z&lt;/LastModified&gt;&lt;/Silect&gt;"
    					Accessibility="Public"
    					Enabled="false"
    					Target="TestCustomerWindows!Test.Customer.Windows.Class"
    					ParentMonitorID="Health!System.Health.AvailabilityState"
    					Remotable="true"
    					Priority="Normal"
    					TypeID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType"
    					ConfirmDelivery="false">
    				<Category>AvailabilityHealth</Category>
    				<AlertSettings AlertMessage="Test.Monitoring.ScriptMonitor.FilesCountInFolder.Alert.Message">
    					<AlertOnState>Warning</AlertOnState>
    					<AutoResolve>true</AutoResolve>
    					<AlertPriority>Normal</AlertPriority>
    					<AlertSeverity>Warning</AlertSeverity>
    					<AlertParameters>
    						<AlertParameter1>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/DomainDnsName$</AlertParameter1>
    					</AlertParameters>
    				</AlertSettings>
    				<OperationalStates>
    					<OperationalState ID="UnderWarning"
    							MonitorTypeStateID="UnderWarning"
    							HealthState="Success" />
    					<OperationalState ID="OverError"
    							MonitorTypeStateID="OverError"
    							HealthState="Error" />
    				</OperationalStates>
    				<Configuration>
    					<TimeoutSeconds>60</TimeoutSeconds>
    					<IntervalSeconds>300</IntervalSeconds>
    					<Threshold>10</Threshold>
    					<folderName>C:\myFolder</folderName>
    				</Configuration>
    			</UnitMonitor>
    		</Monitors>
    		<Overrides>
    			<MonitorPropertyOverride ID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.Group.Override"
    					Context="TestCustomerWindows!Test.Customer.Windows.Group"
    					Enforced="false"
    					Monitor="Test.Monitoring.ScriptMonitor.FilesCountInFolder"
    					Property="Enabled">
    				<Value>true</Value>
    			</MonitorPropertyOverride>
    			<MonitorPropertyOverride ID="Override.For.Test.Monitoring.ScriptMonitor.FilesCountInFolder.Context.Test.Customer.Windows.Class.Property.Enabled.e2ece8fb7b1db97d25fd8d65920256d1"
    					Comment="&lt;Silect&gt;&lt;Op&gt;Created&lt;/Op&gt;&lt;User&gt;myDomain\myAccount&lt;/User&gt;&lt;Previous/&gt;&lt;LastModified&gt;2020-07-27 13:56:27Z&lt;/LastModified&gt;&lt;/Silect&gt;"
    					Context="TestCustomerWindows!Test.Customer.Windows.Class"
    					ContextInstance="e2ece8fb-7b1d-b97d-25fd-8d65920256d1"
    					Enforced="false"
    					Monitor="Test.Monitoring.ScriptMonitor.FilesCountInFolder"
    					Property="Enabled">
    				<Value>true</Value>
    			</MonitorPropertyOverride>
    		</Overrides>
    	</Monitoring>
    	<Presentation>
    		<StringResources>
    			<StringResource ID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.Alert.Message" />
    		</StringResources>
    	</Presentation>
    	<LanguagePacks>
    		<LanguagePack ID="ENU"
    				IsDefault="true">
    			<DisplayStrings>
    				<DisplayString ElementID="Test.Monitoring.FileCountInFolder">
    					<Name>Test.Monitoring.FileCountInFolder</Name>
    					<Description>This MP includes only the monitor which counts files in a folder and alerts, if the file number is greater than threshold.</Description>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder">
    					<Name>Test.Monitoring.ScriptMonitor.FilesCountInFolder</Name>
    					<Description>Created at 2020-07-27 15:53:35 using MP Studio</Description>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.Alert.Message">
    					<Name>Folder has too many files</Name>
    					<Description>The folder C:\myFolder on computer {0} include too many files.</Description>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType">
    					<Name>Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType</Name>
    					<Description>Data Source Module Type for Unit Monitor: Test.Monitoring.ScriptMonitor.FilesCountInFolder</Description>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType"
    						SubElementID="folderName">
    					<Name>folderName</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType"
    						SubElementID="IntervalSeconds">
    					<Name>Interval Seconds</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType"
    						SubElementID="Threshold">
    					<Name>Threshold</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.DataSourceModuleType"
    						SubElementID="TimeoutSeconds">
    					<Name>Timeout Seconds</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.Group.Override">
    					<Name>Test.Monitoring.ScriptMonitor.FilesCountInFolder Group Override</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType">
    					<Name>Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType</Name>
    					<Description>Probe Action Module Type for Unit Monitor: Test.Monitoring.ScriptMonitor.FilesCountInFolder</Description>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType"
    						SubElementID="folderName">
    					<Name>folderName</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType"
    						SubElementID="Threshold">
    					<Name>Threshold</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.ProbeActionModuleType"
    						SubElementID="TimeoutSeconds">
    					<Name>Timeout Seconds</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType">
    					<Name>Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType</Name>
    					<Description>Unit Monitor Type for Unit Monitor: Test.Monitoring.ScriptMonitor.FilesCountInFolder</Description>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType"
    						SubElementID="folderName">
    					<Name>folderName</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType"
    						SubElementID="IntervalSeconds">
    					<Name>Interval Seconds</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType"
    						SubElementID="Threshold">
    					<Name>Threshold</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder.UnitMonitorType"
    						SubElementID="TimeoutSeconds">
    					<Name>Timeout Seconds</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder"
    						SubElementID="OverError">
    					<Name>OverError</Name>
    				</DisplayString>
    				<DisplayString ElementID="Test.Monitoring.ScriptMonitor.FilesCountInFolder"
    						SubElementID="UnderWarning">
    					<Name>UnderWarning</Name>
    				</DisplayString>
    				<DisplayString ElementID="Override.For.Test.Monitoring.ScriptMonitor.FilesCountInFolder.Context.Test.Customer.Windows.Class.Property.Enabled.e2ece8fb7b1db97d25fd8d65920256d1">
    					<Name>Override For Test.Monitoring.ScriptMonitor.FilesCountInFolder Test.Customer.Windows.Class.Property.Enabled.e2ece8fb7b1db97d25fd8d65920256d1</Name>
    					<Description>Created at 2020-07-27 15:56:06 using MP Studio</Description>
    				</DisplayString>
    			</DisplayStrings>
    		</LanguagePack>
    	</LanguagePacks>
    </ManagementPack>

    Best regards

    Birdal

    • Proposed as answer by KUMusr Wednesday, July 29, 2020 10:27 AM
    Monday, July 27, 2020 2:23 PM
  • Hi Birdal,

    As I said in a previous post, the Param() part must be the very first thing at the beginning of the script.

    There can't be anything else before, except comments.

    As a general rule, you should test your scripts outside SCOM before adding them to a management pack!

    Besides that, it looks OK but I didn't actually import it in my environment to test it.
    • Edited by CyrAz Monday, July 27, 2020 3:40 PM
    • Proposed as answer by KUMusr Wednesday, July 29, 2020 10:27 AM
    Monday, July 27, 2020 3:23 PM
  • Hi Cyraz,

    >>> "As I said in a previous post, the Param() part must be the very first thing at the beginning of the script."

    In the previous tests it did not work. After I changed my script, the alert is generated, but only NEW alert, not CLOSED one.

    As you suggested, now I took this Param() in the new script in the first line. Now both, NEW and CLOSED notifications are generated.

    Thank you for your support.

    Best regards

    Birdal 

    Tuesday, July 28, 2020 11:38 AM
  • You also made quite a few other modification... I can see you used MP Studio instead of the Powershell monitor template from cookdown, which is indeed a cleaner way of doing things :)

    Next step : try using Visual Studio with authoring extensions and Kevin Holman's fragments!

    Anyway, glad it works now :)


    Tuesday, July 28, 2020 11:55 AM
  • Hi Cyraz,

    yes, I used MP Studio.

    It is much more better for MPs than SCOM Management Console.

    Thank you for your support.

    Best regards

    Birdal


    • Edited by KUMusr Wednesday, July 29, 2020 10:30 AM
    Wednesday, July 29, 2020 10:30 AM