Chocolately `Get-ExecutionPolicy` - Uncaught ReferenceError: Get is not defined

Viewed 7257

I am following the Chocolately Install steps (Windows 7), but have run into a couple of problems.

Firstly, I've opened Command Prompt (opening it with Run as administrator), but when trying to execute Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')), I get this error:

Uncaught SyntaxError: Unexpected identifier

..with the https: part of my command highlighted.

Further, when I try to execute Get-ExecutionPolicy, it results in:

Uncaught ReferenceError: Get is not defined

Any ideas what could be wrong?

* UPDATE *

When I try the same command in PowerShell, I get this error:

PS C:\Users\mylogin> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtoc ol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString ('https://chocolatey.org/install.ps1')) Exception setting "SecurityProtocol": "Cannot convert value "3312" to type "System.Net.SecurityProtocolType" due to inv alid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Ssl3, Tls"." At line:1 char:85 + Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]:: <<<< SecurityProtocol = [System. Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://ch ocolatey.org/install.ps1')) + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException

Exception calling "DownloadString" with "1" argument(s): "The underlying connection was closed: An unexpected error occ urred on a send." At line:1 char:219 + Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.Se rvicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString <<<< ('https://ch ocolatey.org/install.ps1')) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

2 Answers
  1. Download chocolatey latest version from Chocolatey.org

  2. Rename file extension to .zip

  3. Extract the file

  4. Open PowerShell

  5. Open elevated PowerShell calling:

    Start-Process powershell -Verb runAs
    
  6. Go to the tools folder in the location where you extracted Chocolatey

  7. Call: & .\chocolateyInstall.ps1 to allow Chocolatey to install

  8. Add a path to the choco location to system environment PATH:

    C:\ProgramData\chocolatey\bin
    
  9. Restart your consoles, and VS Code (if you use one)

Chocolatey.org requires TLS 1.2 to be able to connect. This error indicates that you don't have support for that installed:

System.Net.WebClient).DownloadString ('https://chocolatey.org/install.ps1')) Exception setting "SecurityProtocol": "Cannot convert value "3312" to type "System.Net.SecurityProtocolType" due to inv alid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Ssl3, Tls"

The section from the blog post I linked to earlier should help:

If you find yourself provisioning machines such as Windows 7, Windows Server 2008, or older, you will find that those machines will not be able to communicate with the Chocolatey Community Repository after we implement this change. For those instances, you will need to use alternative installation methods for Chocolatey. We strongly recommend using the offline Chocolatey installation as it provides the most flexibility and reliability.

On the Chocolatey install page the requirements are listed:

  • Windows 7+ / Windows Server 2003+
  • PowerShell v2+ (minimum is v3 for install from this website due to TLS 1.2 requirement)
  • .NET Framework 4+ (the installation will attempt to install .NET 4.0 if you do not have it installed)(minimum is 4.5 for install from this website due to TLS 1.2 requirement)

My suggestion would be to fully patch your Windows 7 system, install .NET 4.5 and then try it. Remember Windows 7 has been out of support since January this year.

Related