Skip to content

PowerShell consol is terminated if choco.exe isn't found #1039

@DennisL68

Description

@DennisL68

What New Or Updated Would You Like To See?

In the section https://docs.chocolatey.org/en-us/guides/organizations/set-up-chocolatey-server/#setup-with-powershell-script, replace

if ($null -eq (Get-Command -Name 'choco.exe' -ErrorAction SilentlyContinue)) {
    Write-Warning "Chocolatey not installed. Cannot install standard packages."
    Exit 1
}

with

if ($null -eq (Get-Command -Name 'choco.exe' -ErrorAction SilentlyContinue)) {
    Write-Error  "Chocolatey not installed. Cannot install standard packages." -ErrorAction Stop
}

Why Is It Needed?

Exit will terminate the current PowerShell session, wiping any information needed or opportunity for troubleshooting for the user.
If the script is run from a PowerShell console, the console will be terminated as well.

Additional Context?

I assume Exit 1 is for legacy error handling if the PowerShell script is called from cmd.exe...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions