What This Script Does

The install-chocolatey.ps1 script is the foundation of the entire Chocolatey Scripts toolkit. It provides a fully automated, one-command installation and configuration process for the Chocolatey package manager on Windows 10 and Windows 11 systems. Rather than requiring you to manually navigate the Chocolatey website, copy and paste installation commands, and then separately configure settings, this script handles every step of the process from start to finish in a single execution.

When you run this script, it begins by checking whether Chocolatey is already installed on your system. This is an important first step because the script is designed to be idempotent, meaning you can safely run it multiple times without causing any problems. If Chocolatey is already present, the script will skip the installation phase and move directly to the configuration steps. If Chocolatey is not detected, the script downloads and executes the official Chocolatey installation bootstrap script from the Chocolatey community repository, ensuring you always get the latest stable version.

After the installation completes, the script moves on to configuring several important environment variables and system settings. One of the most significant configuration steps is enabling global confirmation mode. By default, Chocolatey prompts you to confirm every package installation with a Y/N dialog. While this is a reasonable safety measure for interactive use, it becomes a significant obstacle when running automated scripts or batch installations. The global confirmation setting tells Chocolatey to proceed with installations without requiring manual confirmation, which is essential for the other scripts in this toolkit to function correctly.

The script also ensures that the Chocolatey binary directory is properly added to the system PATH environment variable. This is critical because it allows you to run the choco command from any PowerShell or Command Prompt window without needing to specify the full path to the executable. The script checks for the existence of the PATH entry before adding it, avoiding duplicate entries that can accumulate over time and cause issues.

Once installation and configuration are complete, the script runs a choco doctor health check. This built-in Chocolatey diagnostic command verifies that the installation is functioning correctly, checks for common configuration issues, and reports any problems that might prevent packages from being installed or updated properly. Running this check immediately after installation ensures that any issues are caught and reported right away, before you start installing packages.

Throughout the entire process, the script generates detailed log output that is written to %USERPROFILE%\Logs\ChocolateyInstall.log. This log file contains timestamps for every action taken, the results of each configuration change, and the output from the health check. If anything goes wrong during installation, this log file is your first resource for diagnosing the problem. The log uses a structured format that makes it easy to search for specific events or errors.

The script requires Administrator privileges to run because Chocolatey installation involves modifying system-level environment variables and installing files into the C:\ProgramData\chocolatey directory. If you attempt to run the script without elevated privileges, it will detect this and display a clear error message explaining how to run PowerShell as Administrator. This privilege check happens before any changes are made to the system, so there is no risk of a partial installation if you forget to elevate.

One important design decision in this script is its approach to error handling. Every major step in the installation process is wrapped in error-handling logic that captures failures and logs them with detailed context. If the download of the Chocolatey installer fails due to a network issue, for example, the script will log the specific error, provide guidance on common network-related causes, and exit cleanly without leaving the system in a partially configured state. This defensive approach means that even if something goes wrong, your system will not be left in an inconsistent state.

The idempotent design of this script makes it particularly valuable in enterprise and team environments. System administrators can include this script in onboarding procedures, imaging workflows, or configuration management pipelines without worrying about whether Chocolatey might already be installed on a particular machine. Running the script on a system that already has Chocolatey will simply verify and update the configuration settings, then run the health check, ensuring everything is in the expected state regardless of the starting point.

This script also serves as the prerequisite for nearly every other script in the toolkit. Before you can install essential applications, set up automated updates, or configure scheduled maintenance tasks, you need Chocolatey installed and properly configured. Running install-chocolatey.ps1 first ensures that all subsequent scripts have the foundation they need to operate correctly.

Usage

Open an elevated PowerShell window (Run as Administrator) and navigate to the directory containing the script.

# Navigate to the scripts directory
cd C:\path\to\chocolateyScripts

# Run the installation script
.\install-chocolatey.ps1

If you have not yet set the PowerShell execution policy to allow local scripts, you will need to do so first:

# Allow local scripts to run (one-time setup)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

# Then run the installer
.\install-chocolatey.ps1

To verify the installation was successful after the script completes:

# Check Chocolatey version
choco --version

# List installed packages
choco list

What Gets Changed

Running this script makes the following modifications to your system:

  • Chocolatey installation — Installs the Chocolatey package manager to C:\ProgramData\chocolatey if not already present.
  • PATH environment variable — Adds the Chocolatey binary directory (C:\ProgramData\chocolatey\bin) to the system PATH.
  • Global confirmation — Enables the allowGlobalConfirmation Chocolatey feature, suppressing Y/N prompts during package operations.
  • Log file — Creates or appends to %USERPROFILE%\Logs\ChocolateyInstall.log with detailed installation output.
  • Health check — Runs choco doctor to validate the installation and reports results.

Related Scripts