Like and not like

The -like and -notlike operators support simple wildcards. * matches a string of any length (zero or more) and ? matches a single character. Each of the following examples returns true:

'The cow jumped over the moon' -like '*moon*' 
'Hello world' -like '??llo w*' 
'' -like '*' 
'' -notlike '?*' 

Get Mastering Windows PowerShell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.