C
C
Creat1ve2019-01-18 19:46:19
PowerShell
Creat1ve, 2019-01-18 19:46:19

How to escape an asterisk in Powershell?

Good day. How to escape an asterisk in Powershell?
I worked with the HKEY_CLASSES_ROOT\*\ registry branch, so he deleted the entire branch from me. I didn't expect such an ambush from Billy.
UPD1: I found an alternative solution for my task, perhaps not the most elegant, but suddenly it will come in handy for someone:
Get-ChildItem HKLM:\Software\classes\ | Where-Object -property PSChildName -eq "*"
UPD2: Get-ChildItem -LiteralPath HKLM:\Software\classes\*
It also works on Set-Item and Set-ItemProperty
UPD3: Long live insanity, a universal solution has been found. An asterisk en route is shielded by two backticks, i.e. ` (not to be confused with apostrophe and quotation marks). For example, New-Item -Path "HKLM:\Software\classes\``*" -Name "test"
Apparently, the first backtick escapes the second and passes through the string filter, and the second, in turn, lets the interpreter know that the asterisk is a regular character, not a wildcard character.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2019-01-19
kuzmin @sergueik

or via -match
```
HKCU:
pushd Software\Classes
get-childitem | where-object {$_.name -match '\*'}
```
```
Hive: HKEY_CURRENT_USER\Software\Classes
Name Property
---- --------
*
```

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question