What is the difference between PowerShell and cmd.exe syntax?

I run 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 do I need to know about PowerShell syntax to make it work there?

+4
source share
3 answers

@{} defines a hash table in PowerShell, but winrm expects a string argument. Put this argument in quotation marks if you want to run the command directly in PowerShell:

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

In addition, for this you need administrator rights.

+5
source

Or use the special parameter -%, which allows powershell to stop parsing the parameters.

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

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

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

PowerShell will execute executable files that exist on the system.

+1
source

Source: https://habr.com/ru/post/1501489/


All Articles