PowerShell和cmd.exe命令语法有什么区别?

时间:2013-09-10 14:11:44

标签: powershell cmd winrm

我在PowerShell中运行以下命令:

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

正如您所见,这给了我一个错误。但是cmd.exe中的相同命令工作正常:

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

那么,我应该了解PowerShell语法以使其在那里工作?

3 个答案:

答案 0 :(得分:6)

@{}在PowerShell中定义了一个哈希表,但winrm需要一个字符串参数。如果要直接在PowerShell中运行命令,请将该参数放在引号中:

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

此外,您需要管理员权限才能使用。

答案 1 :(得分:2)

或者使用特殊的--%参数,让PowerShell停止解析参数。

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

答案 2 :(得分:1)

您可以在命令前加上cmd / c,并引用它:

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

PowerShell将执行系统中存在的可执行文件。