Home > Software engineering >  How to escape wildcard * in Test-Path for registry?
How to escape wildcard * in Test-Path for registry?

Time:11-06

I'm using Test-Path to check the existence of a registry value under REGISTRY::HKEY_CLASSES_ROOT\*\shell\ but the literal * seems to be recognized as a wildcard. Is there a way to escape it? I tried \* and it didn't seem to work.

CodePudding user response:

Use the -LiteralPath parameter like below -

Test-Path -LiteralPath "REGISTRY::HKEY_CLASSES_ROOT\*\shell\"

From Microsoft's documentation -

-LiteralPath

Specifies a path to be tested. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed. No characters are interpreted as wildcard characters. If the path includes characters that could be interpreted by PowerShell as escape sequences, you must enclose the path in single quote so that they won't be interpreted.

  • Related