PowerShell Matching operators are used to find the entries which matches or do not matches the given criteria.
Matching operators
These operators can be used on multiple operands. When we use multiple operands; the operands should be separated by a comma (“,”). Multiple operands can be used only on left side; right side is a single operand.
-like
and -notlike
operators
These operators finds for the matching (-like
) and not matching (-notlike
) entries from the given operands. -like
, looks for the exact match; whereas -notlike
is do the opposite.
Both of these operators, supports wildcards. When we use wildcards or strings, the entries must be enclosed in quotes (single (‘) or double (“) quotes).
PS C:\> 1 -like 1 True PS C:\> 20, 30, 40 -like 30 30 PS C:\> "hello!" -notlike "hi!" True PS C:\> "Original Film" -like "*film" True PS C:\> ("True", "False", "Bool", "Int") -notlike "Int" True False Bool
Note that, these treats strings as non-case sensitive. That said; the string “Buffer” & “buffer” are same.
-match
and -notmatch
operators
The -match
operator looks for the matching entry; and -notmatch
will do the opposite. These returns True
or False
depending on the given criteria. If multiple values are provided; that means, if the input is a collection; these returns the multiple values depending on the matching result.
Here are some examples;
PS C:\> 111 -match 1 True PS C:\> "Int16", "Int32", "Int64", "Int128" -match "Int" Int16 Int32 Int64 Int128 PS C:\> 1 -notmatch 1 False PS C:\> "Month", "Day", "Year", "Week" -notmatch "Week" Month Day Year
[..] David
One thought on “PowerShell – Matching operators – To find matching entries”