【问题标题】:Error message installing Chocolatey in PowerShell在 PowerShell 中安装 Chocolatey 时出现错误消息
【发布时间】:2013-01-24 03:15:14
【问题描述】:

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

推荐的安装方法是复制并粘贴以下行。

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

但我收到以下错误:

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

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

我尝试了一些应用安装代码的一些位而不是整行,但基本上,@Powershell 之后的任何内容都是一个意外的标记。

【问题讨论】:

  • 这是一个批处理脚本。尝试在 CMD 窗口中运行脚本,而不是在 powershell 控制台中。
  • 在我的框中,@powershell 的行返回错误,因为splatting operator @ 的使用不正确

标签: powershell chocolatey


【解决方案1】:

我无法在我的 Windows 10 64 位操作系统上安装 Chocolatey。我收到powershell not recognized as internal or external command。终于我找到了解决方案,所以对于曾经遇到与我完全相同的问题的人,这里是适合您的解决方案。

之所以会出现这样的错误是因为WindowsPowerShell 路径没有设置。所以请将Path设置为

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

转到环境变量(见下文)。您看到Path 变量,单击编辑,您会看到另一个弹出窗口,其中显示了几个路径。现在单击新建并复制粘贴上述路径。关闭您的 CommandPrompt(admin) 并再次打开它。运行 Chocolatey 给出的命令,现在它开始下载了。

这是一个分步指南:

转到控制面板系统高级系统设置环境变量用户变量对于用户→选择路径变量→单击编辑→单击新建→粘贴此%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\→单击确定 → 你完成了。

【讨论】:

    【解决方案2】:

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

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

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

       $PSVersionTable.PSVersion
      
    3. 启用 PowerShell 脚本的执行?

      set-executionpolicy remotesigned
      
    4. 在 PowerShell 中

      iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
      

    【讨论】:

      【解决方案3】:

      您必须从 cmd.exe(“标准”命令提示符)而不是 PowerShell 启动该行。

      【讨论】:

      猜你喜欢
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-16
      • 2020-02-11
      • 1970-01-01
      • 2018-10-27
      • 2021-11-06
      相关资源
      最近更新 更多