December 7th, 2014

PowerTip: Use PowerShell to See if String Has Wildcard Character

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to determine if a string contains a wildcard character.

Hey, Scripting Guy! Question How can I use Windows PowerShell to determine if a string contains a wildcard character?

Hey, Scripting Guy! Answer Use the static ContainsWildcardCharacters method from the System.Management.Automation.WildcardPattern
           .NET Framework class, for example:

PS C:\> $wc = '*'

PS C:\> $wc

*

PS C:\> [System.Management.Automation.WildcardPattern]::ContainsWildcardCharacters($wc)

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.