Passing a registry key with an asterisk to Test-Path

Question:

I want to run this registry path by Test-Path in PowerShell but it contains an asterisk, which is valid in the registry but not in Windows paths.

The problem is, when I pass it, Test-Path treats the asterisk as a wild card, so this takes a very, very long time because it checks all the sub paths of Classes and is not anything like what I want to test anyway.

Is there any way I can correctly pass that asterisk? Some escape mechanism?

Answer:

Use the -LiteralPath parameter to prevent globbing/wildcard matching.

-LiteralPath<String[]>

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 wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.

Source:

Passing a registry key with an asterisk to Test-Path by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply