[Powershell] Create registry key with space

Hello,

I am creating a registry path with a space, this does not work. The command I am using is a batch file that runs:
powershell.exe New-Item Registry::"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Services\TEST\"

The error is:
New-Item : A positional parameter cannot be found that accepts argument 'Services\TEST'.
At line:1 char:9+ New-Item <<<<  Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Services\TEST
    + CategoryInfo          : InvalidArgument: (:) [New-Item], ParameterBindin   gException    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell   .Commands.NewItemCommand

Can anyone help me fix this problem?
Klantenteam4Asked:
Who is Participating?
 
IanMurphyCommented:
wait a minute. I've just noticed that you are doing this from cmd.exe and not from powershell.

The syntax is different.

powershell.exe -command "& New-Item -path Registry::'HKLM\SOFTWARE\Microsoft\Terminal Services\TEST\'"

Open in new window


Just tried it out and the syntax works for me:

C:\>powershell.exe -command "& New-Item -path Registry::'HKLM\SOFTWARE\Microsoft\TEST\'"


    Hive: HKLM\SOFTWARE\Microsoft


SKC  VC Name                           Property
---  -- ----                           --------
  0   0 TEST                           {}

Open in new window

0
 
SjoerdvWCommented:
Try this one:

powershell.exe New-Item -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Terminal Services\TEST"

Open in new window

0
 
IanMurphyCommented:
The syntax should be

New-Item -path Registry::"HKLM\SOFTWARE\Microsoft\Terminal Services\TEST\"

Open in new window

0
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
Klantenteam4Author Commented:
:( both not working:

 Erreur
0
 
IanMurphyCommented:
¿Are you running powershell 1.0 or have you updated to powershell 2.0?

Never tried this under powershell 1

PowerShell 1.0

PS H:\> $Host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      0      0
PowerShell 2.0(Windows 7)

PS H:\> $Host.Version
Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1      -1

0
 
Klantenteam4Author Commented:
I am using PowerShell v2 in Windows 2008 R2.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.