Passing the registry key with an asterisk to the test path

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

The problem is that when I pass it, Test-Path treats the asterisk as a wild card, so it takes a very, very long time because it checks all the helper paths of Classes and doesn't look like what I want to test anyway.

Can this star be conveyed correctly? Some evacuation mechanism?

 Write-Host "Begin" Test-Path "HKLM:\SOFTWARE\Classes\*\shell\Some shell extension" Write-Host "End" 
+5
source share
1 answer

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

-LiteralPath <String []>

Defines the path to check. Unlike Path, the value of the LiteralPath parameter is used exactly as it is printed. No characters are interpreted as wildcards. If the path contains escape characters, enclose it in single quotation marks. Single quotes indicate that Windows PowerShell does not interpret characters as escape sequences.

 Write-Host "Begin" Test-Path -LiteralPath "HKLM:\SOFTWARE\Classes\*\shell\Some shell extension" Write-Host "End" 
+6
source

All Articles