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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bunyk
  • 7,635
  • 8
  • 47
  • 79

3 Answers3

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
2

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

winrm --% s winrm/config/service @{AllowUnencrypted="true";MaxConcurrentOperationsPerUser="4294967295"}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lars Truijens
  • 42,837
  • 6
  • 126
  • 143
  • 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`". – Peter Mortensen Sep 07 '18 at 17:57
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.

Adil Hindistan
  • 6,351
  • 4
  • 25
  • 28