Powershell script stops working when overriding parameter

I am on SCOM 2019 UR2. I am using the PowerShell Monitoring – Community Management Pack.

I am part way through writing a separate monitor for checking free disk space for the DBA team on their SQL Servers.

I have written a rule that is scheduled to run every 5 minutes. This is a cut down version:


$SplitArg = [string]$Arguments -split(",")

$Device = $SplitArg[0]
$Threshold = [int]$SplitArg[1]

$ServerName = hostname
$Details = ""

ForEach ($DiskDrive in Get-CimInstance -Class CIM_LogicalDisk | Select-Object * | Where-Object Name -EQ $Device){

$DiskDriveFreeGB = [math]::Round($DiskDrive.FreeSpace / 1024 / 1024 / 1024,2)

$PercentFree = ($DiskDrive.FreeSpace / $DiskDrive.Size) * 100
$PercentFreeDecimal = [math]::Round($PercentFree,2)

$Details = "The " + $DiskDrive.Name + " drive on " + $ServerName + " is at " + $PercentFreeDecimal + "%. Which is " + $DiskDriveFreeGB + "GB free.`r`n"

The parameter I pass within the rule is:

$Target/Property[Type=”MicrosoftWindowsLibrary7585010!Microsoft.Windows.LogicalDevice”]/Name$, 45

When the script runs, $Device will become C: and $Threshold becomes 45.

If I override that with something like this (where I change the end number):

$Target/Property[Type=”MicrosoftWindowsLibrary7585010!Microsoft.Windows.LogicalDevice”]/Name$, 65

Then the script stops working correctly. It no longer deciphers $Target/Property[Type=”MicrosoftWindowsLibrary7585010!Microsoft.Windows.LogicalDevice”]/Name$ as C:

$Device will become $Target/Property[Type=”MicrosoftWindowsLibrary7585010!Microsoft.Windows.LogicalDevice”]/Name$

but $Threshold becomes 65

Any thoughts please on why this might be? Thank you.

I always use separate parameters so have no experience with sending in a string argument and splitting it. Maybe you can try to separate them in see it makes any difference?

Thanks Peter. The community management pack says this in the script template:

# Any Arguments specified will be sent to the script as a single string.
# If you need to send multiple values, delimit them with a space, semicolon or other separator and then use split.

So I followed that advice but I am interested in trying what you suggested. Do you have an example please? Are you using the Community Management Pack for Powershell scripting?

I see.

No I dont use the Community MP, I write all my MP:s in Visual Studio. Using a combination of own fragments and Kevin Holmans.

So not sure about the approach with the Community MP