squaredup / Community.PowerShellMonitoring.MP

The PowerShell Monitoring Management Pack extends the System Center Operations Manager (SCOM) console with the ability to create PowerShell based monitoring and automation workflows, including Monitors, Rules, Agent tasks, Diagnostics and Recoveries.
GNU General Public License v3.0
24 stars 4 forks source link

Unable to pass parameter to monitoring script #6

Closed michruch closed 6 years ago

michruch commented 6 years ago

Hi,

I am unable to pass argument to my PowerShell Script Two State Monitor. The saved event shows empty value. Here is my monitor fragment:

MSP_Cluster_Health_check.ps1 #Cluster Health #param($computerName) $api = New-Object -comObject “MOM.ScriptAPI” $PropertyBag = $api.CreatePropertyBag() $api.LogScriptEvent("ThisIsMyParameter",9999,2,"$computerName") $PropertyBag.AddValue(“ComputerName”,$computerName) $PropertyBag $Target/Property[Type="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/PrincipalName$

In general does not matter which parameter I try to use, nothing gets passed.

Is passing arguments to script even possible in this MP?

thanks in advance for any suggestion

michruch commented 6 years ago

Of course param() is not commented, opposite to my example above

shadeon commented 6 years ago

It's possible, you just have to receive all parameters as a string value named Arguments due to limitations of the templates. The templates should already have param([string]$Arguments) specified, so just change it back to that.

If you need to pass multiple args, just add a delimiter between each and use the string.split method in your script to extract them.

It's also worth noting that you can add dynamic property references directly into the script, and SCOM will inject them prior to running the script on each target, so the below also works perfectly fine:

$computerName = '$Target/Property[Type="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/PrincipalName$'

michruch commented 6 years ago

Hi Shadeon,

This works fine. Thank you for your help