PML 2 Plugin Development Guide
Plugin Operators
This document describes the operators available in the PML 2 plugin system.
PML 2 plugins support value comparison operators and logical operators; some operators have two forms.
1. Value comparison operators
PML 2 currently supports the following value comparison operators:
| Operator | Alias | Description | Example |
|---|---|---|---|
-eq | == | Checks whether the values on both sides are equal. Comparison uses object.Equals. | {{ctx.data.version}} == "26.2.0"{{ctx.data.version}} -eq "26.2.0" |
-ne | != | Checks whether the values on both sides are not equal. This is the negation of object.Equals. | {{ctx.data.version}} != "26.2.0"{{ctx.data.version}} -ne "26.2.0" |
-gt | > | Checks whether the left value is greater than the right value. | {{ctx.variables.count}} > 5{{ctx.variables.count}} -gt 5 |
-lt | < | Checks whether the left value is less than the right value. | {{ctx.variables.count}} < 5{{ctx.variables.count}} -lt 5 |
-ge | >= | Checks whether the left value is greater than or equal to the right value. | {{ctx.variables.count}} >= 5{{ctx.variables.count}} -ge 5 |
-le | <= | Checks whether the left value is less than or equal to the right value. | {{ctx.variables.count}} <= 5{{ctx.variables.count}} -le 5 |
-like | none | Checks whether the left value matches the wildcard pattern on the right. * matches any sequence of characters (including an empty one), ? matches a single character, and every other character is matched literally. Matching is whole-string and case-insensitive. | {{ctx.data.os}} -like "Windows *" |
-notlike | none | Checks whether the left value does not match the wildcard pattern on the right (negation of -like). | {{ctx.data.os}} -notlike "Windows *" |
-match | none | Checks whether the left value matches the regular expression on the right (.NET syntax). Matching is by substring, so ^ / $ anchors are not required; case-insensitive. Returns false if the pattern is not a valid regular expression. | {{ctx.data.os}} -match "Windows \d+" |
-notmatch | none | Checks whether the left value does not match the regular expression on the right (negation of -match). | {{ctx.data.os}} -notmatch "Windows \d+" |
-contains | none | If both sides are strings, checks whether the left value contains the right value; if the left side is a collection, checks whether the left collection contains the right value. (x ∋ y or x ⊇ y) | {{ctx.data.os}} -contains "Windows" |
-notcontains | none | If both sides are strings, checks whether the left value does not contain the right value; if the left side is a collection, checks whether the left collection does not contain the right value. (x ∌ y or x ⊅ y) | {{ctx.data.os}} -notcontains "Windows" |
-in | none | If both sides are strings, checks whether the left value is contained in the right value; if the right side is a collection, checks whether the left value is contained in the right collection. (x ∈ y or x ⊆ y) | "Windows" -in {{ctx.data.os}} |
-notin | none | If both sides are strings, checks whether the left value is not contained in the right value; if the right side is a collection, checks whether the left value is not contained in the right collection. (x ∉ y or x ⊄ y) | "Windows" -notin {{ctx.data.os}} |
-like / -notlike use wildcard semantics while -match / -notmatch use regular expression semantics; the two cannot be mixed.
To match "Windows followed by digits", write {{ctx.data.os}} -match "Windows \d+";
with -like "Windows \d+" the \d is treated as literal characters.If an unsupported operator is used, the comparison always returns false.
Some operators follow PowerShell script syntax; you can read about them in PowerShell operators.
2. Logical operators
PML 2 currently supports the following logical operators:
| Operator | Alias | Description | Example |
|---|---|---|---|
-and | && | Computes the logical AND of the expressions on both sides. If x and y both evaluate to true, x && y is true; otherwise it is false. If x evaluates to false, y is not evaluated. | {{ctx.data.version}} -eq "26.2.0" && {{ctx.data.os}} -contains "Windows" |
-or | || | Computes the logical OR of the expressions on both sides. If either x or y evaluates to true, x || y is true; otherwise it is false. If x evaluates to true, y is not evaluated. | {{ctx.data.version}} -eq "26.2.0" || {{ctx.data.os}} -notcontains "Windows" |
-xor | ^| or ^ | Computes the logical XOR of the expressions on both sides. If x and y evaluate differently, x ^| y is true; otherwise it is false. | {{ctx.data.version}} -eq "26.2.0" ^| {{ctx.data.os}} -contains "Windows" |
See MSDN to learn more about logical operators.
3. Arithmetic operators
PML 2 currently supports the following arithmetic operators:
| Operator | Description | Example |
|---|---|---|
+ | Addition: computes the sum of the values on both sides. | {{ctx.variables.count}} + 5 |
- | Subtraction: computes the difference of the values on both sides. | {{ctx.variables.count}} - 5 |
* | Multiplication: computes the product of the values on both sides. | {{ctx.variables.count}} * 5 |
/ | Division: computes the quotient of the values on both sides. | {{ctx.variables.count}} / 5 |
% | Modulo: computes the remainder of the values on both sides. | {{ctx.variables.count}} % 5 |
// | Integer division: computes the integer part of the quotient of the values on both sides. | {{ctx.variables.count}} // 5 |
** or ^ | Exponentiation: raises the left value to the power of the right value. | {{ctx.variables.count}} ** 5 |