Registry and special characters

Hi all,

Me again with yet another question.

I’m trying to create a new registry item in the HKCR:*\shell\ environment.
Sadly though, I can’t get Powershell to accept the wildcard character as a normal character.
I’ve tried using the backtick and other escape characters, but it just doesn’t seem to work.

What doesn’t work:

New-Item -Path 'HKCR:\*\shell\takeownership\' -Name test –Force

What does work:

Set-Location -LiteralPath 'HKCR:\*\shell'
New-Item -Name 'takeownership'

I really would like to get the first one working, because it’s part of a function I created for creating registry keys.
If anyone has a solution to this problem, please let me know.

Thanks in advance & regards,

T.O.

Normally you can escape those wildcard-supporting paths by putting the special characters in square brackets, but in my testing, that didn’t seem to work. Maybe New-Item needs a -LiteralPath parameter.

In the meantime, you might just need to work around this. If you want to use the registry provider and New-Item, you could split the path and use Set-Location -LiteralPath, or maybe you could resort to calling the .NET methods directly. Something like this:

(Get-Item HKCR:\).CreateSubKey('*\shell\takeownership\test')