[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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Klantenteam4Author Commented:
:( both not working:

 Erreur
0
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Klantenteam4Author Commented:
I am using PowerShell v2 in Windows 2008 R2.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.