Search code examples
powershellregistrywhitespacequoting

Using a space and slash with New-Item


So I have to add this registry entry using PowerShell and sadly it has a space and a / in it. I'd like to know what the syntax is for adding this kind of entry or a new method because I'm unable to find a good answer. To be clear this needs to create a key called RC4 128/128 under the ciphers folder.

New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers" -Name RC4 128/128

This is the error I got below:

New-Item : A positional parameter cannot be found that accepts argument '128/128'. At line:1 char:1 + New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProvid ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-Item], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewItemCommand


Solution

  • It's not a Powershell issue, but it's an issue with the way the New-Item cmdlet is written.

    Here's how you do it though:

    ([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $env:COMPUTERNAME)).CreateSubKey('SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\RC4 128/128')

    Credit: u/bhudlemeyer from reddit

    It's very strange that they require you to create a key path with a space and slash because even regedit doesn't allow that.