Error message installing Chocolatey in PowerShell
Asked Answered
D

3

13

I'm trying to install Chocolatey to use with PowerShell.

The recommended way to install it is copy and paste the following line.

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

But I get the following error:

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 is set as RemoteSigned and I'm running Powershell v3

I tried some apply some bits of the installation code rather than the whole line, but basically, anything after @Powershell is an unexpected token.

Disorientate answered 8/2, 2013 at 11:5 Comment(2)
It's a batch script. Try running the script in a CMD window, not in a powershell console.Bejewel
In my box the line return error at @powershell for the incorrect use of splatting operator @Duodenal
C
21

You must start that line from cmd.exe (a "standard" command prompt), not from PowerShell.

Cornu answered 8/2, 2013 at 11:53 Comment(2)
You're absolutely right. I also had to add powershell.exe folder to the PATH variable: C:\Windows\SysWOW64\WindowsPowerShell\v1.0;Disorientate
Yep, take a look at this for the powershell command: github.com/chocolatey/chocolatey/wiki/InstallationNedanedda
P
5

In PowerShell v3+ the easiest way is:

  1. Open a PowerShell window (run as administrator)

  2. Check the version of PowerShell is greater than 3:

     $PSVersionTable.PSVersion
    
  3. Enable execution of PowerShell scripts?

    set-executionpolicy remotesigned
    
  4. In PowerShell

    iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
    
Packard answered 3/1, 2017 at 9:23 Comment(0)
M
1

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.

Molybdous answered 23/4, 2017 at 3:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.