Checking Array Content With Wildcards

by Aug 6, 2011

In a previous tip we illustrated how -like can work on array. To iterate on that, check out how -like (in contrast to -contains) allows the use of wildcards to check for array elements:

PS> 'Peter', 'Mary', 'Martin' -contains 'Mary'
True
PS> 'Peter', 'Mary', 'Martin' -contains 'Ma*'
False
PS> 'Peter', 'Mary', 'Martin' -like 'Ma*'
Mary
Martin
PS> @('Peter', 'Mary', 'Martin' -like 'Ma*').Count -gt 0
True

Twitter This Tip!
ReTweet this Tip!