bcurran3 / ChocolateyPackages

My published Chocolatey packages
206 stars 94 forks source link

Install failing as System #318

Closed Nialith20 closed 1 year ago

Nialith20 commented 1 year ago

Morning, Thanks for the scripts.

I have a couple hundred devices I need to clean about 40gb of files from. When running choco install 'choco-cleaner' -source 'https://community.chocolatey.org/api/v2/' as a device admin, Cleaner installs no issues and scripts function perfectly.

When running as system I get the following error 2023-02-24 09:11:52,381 8636 [DEBUG] - Running Update-SessionEnvironment 2023-02-24 09:11:52,382 8636 [INFO ] - VERBOSE: Refreshing environment variables from the registry. 2023-02-24 09:11:52,502 8636 [ERROR] - ERROR: Cannot bind argument to parameter 'Path' because it is an empty string. 2023-02-24 09:11:52,506 8636 [DEBUG] - Built-in PowerShell host called with ['[System.Threading.Thread]::CurrentThread.CurrentCulture = '';[System.Threading.Thread]::CurrentThread.CurrentUICulture = ''; & import-module -name 'C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1'; & 'C:\ProgramData\chocolatey\helpers\chocolateyScriptRunner.ps1' -packageScript 'C:\ProgramData\chocolatey\lib\choco-cleaner\tools\chocolateyinstall.ps1' -installArguments '' -packageParameters '''] exited with '-1'.

I've had a google and made some changes to chocolatey's functions but still no luck.

Looks like it's happening just before Running Install-ChocolateyPowershellCommand -packageName 'choco-cleaner' -psFileFullPath 'C:\tools\BCURRAN3\choco-cleaner.ps1'

I can confirm this is happening on multiple devices, in multiple environments (same version of chocolatey 1.1.0 & 1.3.0) and chocolatey-core.extension 1.4.0 Windows 10 - 1909 or higher

running choco install 'winrar' -source 'https://community.chocolatey.org/api/v2/' works fine (just to confirm it's not something dumb with choco install)

Can be replicated with PStools Any thoughts of things I can try to get this running? log files include failure as system first and success as .\administrator.

choco.summary.log chocolatey.log

Nialith20 commented 1 year ago

After a lot of troubleshooting, I found that this was an issue with: if (Test-Path "$ENV:ChocolateyInstall\bin\$script") {Remove-Item "$ENV:ChocolateyInstall\bin\$script" -Force

$ENV:ChocolateyInstall is not being populated as system.

To get this going I set $scriptDir = $ENV:SystemDrive + "\Programdata\chocolatey\tools\BCURRAN3"

and commented out Update-Config

This doesn't address the issue but will get it running in a pinch. I'm not sure why this package has the issue and not others as it seems more of a chocolatey issue then choco-cleaner one.

bcurran3 commented 1 year ago

$ENV:ChocolateyInstall/%ChocolateyInstall% is the location that Chocolatey is installed. It should be a system wide variable created when Chocolatey is installed. It's used frequently by (my) packages. If you don't have that environment variable I highly suggest you report it as a bug to chocolatey and also force it out to your systems, using group policy is probably easiest.