Search code examples
powershellregistry

How to escape forward slash '/' in path with PowerShell


Recently, I wrote a powershell script to handle some infomation in registry. But when I access the registry path in the image by use cmdlet

Get-ChildItem -Path 'HKLM:\SOFTWARE\Classes\MAPI/Attachment'

I got a error info:

Get-ChildItem: Cannot find path 'HKEY_LOCAL_MACHINE\SOFTWARE\Classes\MAPI\Attachment' because it does not exist.

I know it's because of the forward slash / in the path, but I want to know how can I escape it, or how can I access the path by any method.

enter image description here


Solution

  • A work arround, if you really want to get the object you can use :

    Get-ChildItem -Path 'HKLM:\SOFTWARE\Classes' | where {$_.name -like "*MAPI/Attachment"}
    

    To be more efficient as @mklement0 comment suggest :

    Get-ChildItem -Path 'HKLM:\SOFTWARE\Classes' | where PSChildName -eq 'MAPI/Attachment'