Registry and special characters

Welcome Forums General PowerShell Q&A Registry and special characters

This topic contains 1 reply, has 2 voices, and was last updated by

3 years, 8 months ago.

  • Author
  • #22642

    Points: 0
    Rank: Member

    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,


  • #22643

    Points: 0
    Rank: Member

    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')

The topic ‘Registry and special characters’ is closed to new replies.