12

我正在尝试安装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 之后的任何内容都是一个意外的标记。

4

3 回答 3

20

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

于 2013-02-08T11:53:12.740 回答
5

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

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

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

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

    set-executionpolicy remotesigned
    
  4. 在 PowerShell 中

    iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
    
于 2017-01-03T09:23:58.793 回答
0

I was unable to install Chocolatey on my Windows 10 64-bit OS installation. I was getting powershell not recognized as internal or external command. Finally I found the solution, so to people who ever facing the exact same problem as I did, here is the solution for you.

The reason why you get such an error is because the WindowsPowerShell path is not set. So kindly set the Path as

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

Go to Environment variable (see below). You see that Path variable, click on Edit and you see one more pop-up window, which shows a couple of paths there. Now click on New and copy-paste the above path. Close your CommandPrompt(admin) and open it again. Run the command given by Chocolatey, and now it starts downloading.

Here is a step-by-step guide:

Go to Control PanelSystemAdvanced System SettingsEnvironment VariablesUser variable for Users → Select Path Variable → click Edit → Click on New → paste this %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ → Click OK → you're done.

于 2017-04-23T03:38:05.073 回答