Add registry key with forward slash


I’m having problem adding a registry key with a forward slash:

$HKCURegistrySettings = {
Set-RegistryKey -Key ‘HKCU\Software\X\’ -SID $UserProfile.SID

Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings.ToString


I have searched and tried many things but there seems not to be a soluiton. Please help.

PowerShell interprets a forward slash as a path separator. You will need to do something like this to write a forward slash to the registry:

$HKCURegistrySettings = {
Set-RegistryKey -Key “HKCU\Software\X\https:$([char]0x2F)$([char]0x2F)$([char]0x2F)” -SID $UserProfile.SID

This doesn’t work. Here’s my code:
[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key “HKCU\Software\SoftPlan Systems Inc.\SoftPlan Workstation\16.3.4\C:$([char]0x2F)Program Files$([char]0x2F)SoftPlan2014\SoftPlan Folders” -Name ‘Projects’ -Value “S:$([char]0x2F)” -SID $UserProfile.SID
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings

This creates a series of keys named C: \ Program Files \ SoftPlan2014 \ SoftPlan Folders </code> and then refuses to create the S:\ value because the Path doesn’t exist:

[03-18-2016 09:06:22.428] [Post-Installation] [Set-RegistryKey] :: Failed to set value [S:/] for registry key [Registry::HKEY_CURRENT_USER
Software\SoftPlan Systems Inc.\SoftPlan Workstation\16.3.4\C:/Program Files/SoftPlan2014\SoftPlan Folders] [Projects].
Error Record:

Message : Cannot find path ‘HKEY_CURRENT_USER\Software\SoftPlan Systems Inc.\SoftPlan Workstation\16.3.4\C:/Program
Files/SoftPlan2014\SoftPlan Folders’ because it does not exist.
InnerException :

FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemPropertyCommand
ScriptStackTrace : at Set-RegistryKey<Process>, \5000m45\packagesource$\Software_8\Softplan_Educational_Workstation_2014\AppDeployTo
olkit\AppDeployToolkitMain.ps1: line 3737
at <ScriptBlock>, <No file>: line 1

PositionMessage : At \5000m45\packagesource$\Software_8\Softplan_Educational_Workstation_2014\AppDeployToolkit\AppDeployToolkitMain.ps1:3
737 char:14
+ $null = New-ItemProperty -LiteralPath $key -Name $name -Value $value -Prope …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I apologize for the mess. I have no idea how to put in code nicely.

Have you tried the apostrophe-like character ` in front of your slash character? It’s called grave accent according to

DEC; OCT; HEX; BIN; Symbol; HTML; Number; HTML; Name; Description;
96 140 60 01100000 ` ` Grave accent

Now, this wysisyg is not very “character friendly” but your string would look something like this (if all characters are allowed in here):

Normally solves my scripts involving spooky characters.

Ok, my example of your string got messed up by the site, but I think you get it… put one ` in front of every / and I think you’re good to go.

Did you try it? It doesn’t work for me. I try

Set-RegistryKey -Key "HKCU:\TEMPORARY'c:/temp/"

and powershell still just interprets them as backslashes and gives me:
HKCU \ TEMPORARY \ C: \ temp
HKCU \ TEMPORARY \ C: \ emp (for some reason)

In the above post I did put backquotes in front of the forward slashes.

No I didn’t try your script out. I did however run the following through a PS console without any issues:

Set-ItemProperty -Name TESTURL -Value “” -Path HKCU:\SOFTWARE\TEST
Set-ItemProperty -Name TESTPATH -Value “C://.com” -Path HKCU:\SOFTWARE\TEST\

Comes out as two REG_SZ strings with both slashes backslashes formatted correctly. The 2nd one obviously has a messed up value, but proved to me that came out as expected in the registry.

Might be something in the Function Set-RegistryKey that messes things up. It does go beyond the normal PS cmdlets for adding items in the registry, so might be.

Again, please mind the automatic formatting on the site. I did put a ` in front of every special character and surrounded the entire value string with quotation marks.

I’m having problems with the key name, not the value of a property. I’ve created a bug report on the tracker for it that has more detail about what I’ve tried.
I can’t seem to create a key with forward slashes in it or write to an existing key with the same. Values seem to work out fine.

My bad, sorry about that.

Meanwhile waiting for the bug report to be carried out, you could try:

$key = (get-item HKCU:).OpenSubKey(“SOFTWARE\TEST”, $true)

Seems work for keys without hassle.

found at

That’s a start. Thanks.
If that works I’ve just got to figure out how to write a propery/value into a key with a forward slash in the name.