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?
Write-Host "Begin"
Test-Path "HKLM:\SOFTWARE\Classes\*\shell\Some shell extension"
Write-Host "End"
One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .
A registry key can be thought of as being a bit like a file folder, but it exists only in the Windows Registry. Registry keys contain registry values, just like folders contain files. Registry keys can also contain other registry keys, which are sometimes referred to as subkeys.
The Test-Path cmdlet determines whether all elements of the path exist. It returns $True if all elements exist and $False if any are missing. It can also tell whether the path syntax is valid and whether the path leads to a container or a terminal or leaf element.
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.
Write-Host "Begin"
Test-Path -LiteralPath "HKLM:\SOFTWARE\Classes\*\shell\Some shell extension"
Write-Host "End"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With