I have found that -match operator does not always work with the $Matches object. For instance, if I use this command, @(1,2,3) -match "\d"and then check $Matches it is empty. Based on this, I have always wondered: what are the rules for when $Matches gets written to and when it does not get written to?

by poshoholic at 2012-08-29 09:30:06

AFAIK the rule is simple: if you are using -match against a single item that is a collection, even if it is a collection of only one item, then $matches is not written to. If you are using -match against a single item that is not a collection, then $matches is written to.

by willsteele at 2012-08-29 11:23:54

You were exactly right Kirk. Thanks for the clarification. I got it now.