1

Hi i'm just wondering im currently creating folder on my registry this is my code

function AddMachineRegistry{
    param(
    [string] $registryPath = $(throw "registryPath is a required parameter"),
    [string] $name = $(throw "name is a required parameter"),
    [int] $value = $(throw "value is a required parameter")
    )

    IF(!(Test-Path $registryPath))
    {
        New-Item -Path $registryPath -ItemType Key -Force | Out-Null     
    }

    New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType DWORD -force | Out-Null
}

and tried to used it like this

AddMachineRegistry "HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 40/128\" "Enabled" 0

basically im trying to create a key with the name of "RC4 40/128" but when i execute it it creates "RC4 40" folder and under that it creates "128"

im just wondering is it possible to create that? since im currently using "New-Item" and just giving it a path. i want my folder to named "RC4 40/128"

bRaNdOn
  • 1,060
  • 4
  • 17
  • 37
  • 1
    Possible duplicate of [How to create a registry entry with a forward slash in the name](https://stackoverflow.com/questions/18218835/how-to-create-a-registry-entry-with-a-forward-slash-in-the-name) – J. Bergmann Jul 28 '17 at 09:10
  • 1
    Just for the correct terminology : Regedit is a tool, you can't create a key "in" regedit (you can do it using regedit), you create a key in the registry. – bluuf Jul 28 '17 at 16:25

2 Answers2

1

The easiest way will be invoking & REG ADD (basically, using CMD for the task) since PowerShell wants to interpret the forward slash as a delimiter. I just had a problem at work recently where I ran into this problem and could not find any solutions beyond that one.

A small tip: | Out-Null is a very slow operation and if you plan on calling anything with it to scale, I'd recommend using $Null = or [Void]( ... )

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
0

Normaly you must use:

New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\" -Name "RC4 40/128" -PropertyType DWORD -Value 0

In this case it will we be:

AddMachineRegistry "HKLM:\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\" "RC4 40/128" 0

There is no need to backslashes the "/". Alternative: you can put path in ' ' instead " ". Commands in ' ' change special characters to normal chars.

KlapenHz
  • 73
  • 10