在PowerShell中安装Chocolatey的错误消息

Raf*_*lGP 8 powershell chocolatey

我正在尝试安装Chocolatey以与PowerShell一起使用.

建议的安装方法是复制并粘贴以下行.

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

At line:1 char:13
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object  ...
+             ~~~~~~~~~~
Unexpected token '-NoProfile' in expression or statement.
At line:1 char:24
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object  ...
+                        ~~~~~~~~~~~~~~~~
Unexpected token '-ExecutionPolicy' in expression or statement.
At line:1 char:150
+ ... nstall.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin
+                    ~~
The token '&&' is not a valid statement separator in this version.
At line:1 char:1
+ @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object  ...
+ ~~~~~~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@powershell' can be used only as
an argument to a command. To reference variables in an expression use '$powershell'.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken
Run Code Online (Sandbox Code Playgroud)

ExecutionPolicy设置为RemoteSigned,我正在运行Powershell v3

我尝试了一些应用安装代码而不是整行,但基本上,在@Powershell之后的任何东西都是意外的令牌.

Dav*_*ant 17

您必须从cmd.exe("标准"命令提示符)开始该行,而不是从PowerShell开始.

  • 你是绝对正确的.我还必须将powershell.exe文件夹添加到PATH变量:C:\ Windows\SysWOW64\WindowsPowerShell\v1.0; (2认同)

Dom*_*nzi 5

在 PowerShell v3+ 中,最简单的方法是:

  1. 打开 PowerShell 窗口(以管理员身份运行)

  2. 检查PowerShell的版本是否大于3:

     $PSVersionTable.PSVersion
    
    Run Code Online (Sandbox Code Playgroud)
  3. 启用 PowerShell 脚本的执行?

    set-executionpolicy remotesigned
    
    Run Code Online (Sandbox Code Playgroud)
  4. 在 PowerShell 中

    iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
    
    Run Code Online (Sandbox Code Playgroud)