Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The term 'choco.exe choco.exe' is not recognized as a name of a cmdlet, function, script file, or executable program. #69

Closed
Jaykul opened this issue Mar 31, 2023 · 0 comments · Fixed by #70

Comments

@Jaykul
Copy link
Contributor

Jaykul commented Mar 31, 2023

Whenever you use Get-Command to find a command, you must ensure that you only get one result back.

if (-not ($chocoCmd = Get-Command 'choco.exe' -CommandType 'Application' -ErrorAction 'SilentlyContinue'))

Otherwise, if (for instance) something modifies your Env:PATH and appends the chocolatey path a second time ...
Let's say, hypothetically, that one of these has extra slashes, or the wrong slashes or a slash on the end:

if ($($env:Path).ToLower().Contains($($chocoExePath).ToLower()) -eq $false)
{
$env:Path = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine)
}

You'll end up getting the error " The term 'choco.exe choco.exe' is not recognized as a name of a cmdlet" down here:

&$chocoCmd $ChocoArguments

Jaykul added a commit to Jaykul/Chocolatey that referenced this issue Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant