July 16th, 2013

PowerTip: Use PowerShell to Check String for a Match

Doctor Scripto
Scripter

Summary: Learn how to check a string to see if it contains another string.

Hey, Scripting Guy! Question How can I use Windows PowerShell to check a string to see if it contains another string?

Hey, Scripting Guy! Answer Use the –Match operator:

PS C:\> $a = [string]”This string contains a number of letters”

PS C:\> $a -match ‘a number’

True

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.

Feedback