5

I am running the following command in PowerShell:

PS C:\Users\adminaccount> winrm s winrm/config/service @{AllowUnencrypted="true";
MaxConcurrentOperationsPerUser="4294967295"}
Error: Invalid use of command line. Type "winrm -?" for help.

Which gives me an error, as you could see. But the same command in cmd.exe works fine:

C:\Users\adminaccount>winrm s winrm/config/service @{AllowUnencrypted="true";
MaxConcurrentOperationsPerUser="4294967295"}
Service
...

So, what should I know about PowerShell syntax to get this working there?

2
  • Shouldn't " be quoted (e.g. by `)? Commented Sep 6, 2018 at 16:37
  • @PeterMortensen I don't know, I have last touched PowerShell of the version 3, and never worked with it any more. But why do you think that " should be quoted? Commented Sep 11, 2018 at 10:24

3 Answers 3

6

@{} defines a hashtable in PowerShell, but winrm expects a string argument. Put that argument in quotes if you want to run the command directly in PowerShell:

winrm s winrm/config/service '@{AllowUnencrypted="true"; MaxConcurrentOperationsPerUser="4294967295"}'

Also, you need admin privileges for this to work.

Sign up to request clarification or add additional context in comments.

Comments

2

Or use the special --% parameter which lets PowerShell stop parsing the parameters.

winrm --% s winrm/config/service @{AllowUnencrypted="true";MaxConcurrentOperationsPerUser="4294967295"}

1 Comment

This works, but not if there a PowerShell in there that should be expanded. Example: ` + $redirectSpec` at the end and $redirectSpec containing ">> _output_2018-09-07T195607.txt".
1

You can prefix your command with cmd /c and quote it like:

cmd /c "winrm s winrm/config/service @{AllowUnencrypted=`"true`";
MaxConcurrentOperationsPerUser=`"4294967295`"}" 

PowerShell will execute executables that exist in the system.

3 Comments

Still not working: "Error: Invalid use of command line. Type "winrm -?" for help."
Well, I was trying to explain the difference as you asked. You will need to take care of special chars, escape quotes etc. See updated command
Depending on the command, you might need to start the Powershell in Admin mode...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.