简体   繁体   English

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

[英]What is the difference between PowerShell and cmd.exe command syntax?

I am running the following command in PowerShell: 我在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: 但是cmd.exe中的相同命令可以正常工作:

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? 那么,我应该对PowerShell语法有什么了解才能使它在那里工作?

@{} defines a hashtable in PowerShell, but winrm expects a string argument. @{}在PowerShell中定义了哈希表,但winrm需要一个字符串参数。 Put that argument in quotes if you want to run the command directly in PowerShell: 如果要直接在PowerShell中运行命令,请在引号中加上引号:

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

Also, you need admin privileges for this to work. 另外,您需要管理员权限才能正常工作。

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

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

You can prefix your command with cmd /c and quote it like: 您可以在命令前加上cmd / c并将其引用为:

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

PowerShell will execute executables that exist in the system. PowerShell将执行系统中存在的可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM