You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (Test-ProcessAdminRights) {
# HKCU:\Environment may not exist, which happens sometimes with Server Core
Set-EnvironmentVariable -Name $variableName -Value $variableValue -Scope Machine
}
However, Set-EnvironmentVariable doesn't have Scope parameter.
What is Expected?
In order to set machine-level enviornment variable, the Target parameter must be used instead.
Sample: Set-EnvironmentVariable -Name $variableName -Value $variableValue -Target Machine
Docs from Get-Help:
Execute install commands on Windows 11 host (23H2):
Set-ExecutionPolicy Bypass -Scope Process -Force
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
System Details
Operating System: Windows 11 Enterprise multi-session 23H2
Windows PowerShell version: 5.1.22621.4249
Chocolatey CLI Version: 2.3.0
Chocolatey Licensed Extension version:
Chocolatey License type:
Terminal/Emulator: Powershell ISE
Installed Packages
None
Output Log
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/2.3.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/2.3.0 to C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\chocolatey.zip to C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall
Remove-Item : Cannot remove item C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\tools\chocolateyInstall\helpers\Chocolatey.PowerShell.dll: Access to the path
'C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\tools\chocolateyInstall\helpers\Chocolatey.PowerShell.dll' is denied.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1029 char:29
+ ... Remove-Item -LiteralPath $currentArchiveEntryFileInfo.Ful ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Users\devops....PowerShell.dll:FileInfo) [Remove-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : RemoveFileSystemItemUnAuthorizedAccess,Microsoft.PowerShell.Commands.RemoveItemCommand
Installing Chocolatey on the local machine
Set-EnvironmentVariable : A parameter cannot be found that matches parameter name 'Scope'.
At C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\tools\chocolateyInstall\helpers\functions\Install-ChocolateyEnvironmentVariable.ps1:117 char:83
+ ... mentVariable -Name $variableName -Value $variableValue -Scope Machine
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-EnvironmentVariable], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Set-EnvironmentVariable
Set-EnvironmentVariable : A parameter cannot be found that matches parameter name 'Scope'.
At C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\tools\chocolateyInstall\helpers\functions\Install-ChocolateyEnvironmentVariable.ps1:103 char:79
+ ... mentVariable -Name $variableName -Value $variableValue -Scope $variab ...
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-EnvironmentVariable], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Set-EnvironmentVariable
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Set-EnvironmentVariable : A parameter cannot be found that matches parameter name 'Scope'.
At C:\Users\devops\AppData\Local\Temp\chocolatey\chocoInstall\tools\chocolateyInstall\helpers\functions\Install-ChocolateyEnvironmentVariable.ps1:103 char:79
+ ... mentVariable -Name $variableName -Value $variableValue -Scope $variab ...
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-EnvironmentVariable], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Set-EnvironmentVariable
Additional Context
No response
The text was updated successfully, but these errors were encountered:
I suspect the issue you are having is related to the earlier error. Are you installing within an elevated session? I also note you are running from PowerShell ISE which could be causing issues.
@pauby Ah, I thought Set-EnvironmentVariable function was part of some default PowerShell module.
Turns out, there is a conflict between Chocolatey's function, and a function from another module who also happen to have a function with the same name, but different signature.
Fixed by uninstalling module with conflicting function
Checklist
What You Are Seeing?
Chocolatey's install script downloads
Install-ChocolateyEnvironmentVariable.ps
file which uses the following invalid code:https://github.com/chocolatey/choco/blame/c8326fb81bb8f8bb741b3a18d2326d6f00bf43a4/src/chocolatey.resources/helpers/functions/Install-ChocolateyEnvironmentVariable.ps1#L117
However,
Set-EnvironmentVariable
doesn't haveScope
parameter.What is Expected?
In order to set machine-level enviornment variable, the
Target
parameter must be used instead.Sample:
Set-EnvironmentVariable -Name $variableName -Value $variableValue -Target Machine
Docs from
Get-Help
:How Did You Get This To Happen?
Execute install commands on Windows 11 host (23H2):
System Details
Installed Packages
None
Output Log
Additional Context
No response
The text was updated successfully, but these errors were encountered: