Recommand · October 14, 2021 0

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

Could replace the forward slash with the unicode character:

Get-ChildItem -Path 'HKLM:\SOFTWARE\Classes\MAPI/Attachment'.Replace("/",[char]0x2215)

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"}