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

When no hook scripts are installed you cannot install/upgrade a package on a system using PowerShell 2 #3088

Closed
4 tasks done
corbob opened this issue Mar 23, 2023 · 8 comments · Fixed by #3092
Closed
4 tasks done
Assignees
Milestone

Comments

@corbob
Copy link
Member

corbob commented Mar 23, 2023

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my problem.
  • I have verified this is not an issue for a specific package.
  • I have verified this issue is not security related.

What You Are Seeing?

On a system with just PowerShell 2 (and somehow at least one Windows 10 system with PowerShell 2 enabled), when you try to install or upgrade any package, you receive an error:

Cannot bind parameter 'Process'. Cannot convert the "BaseName" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
ERROR: The expression after '&' in a pipeline element produced an invalid object. It must result in a command name, script block or CommandInfo object.

What is Expected?

Packages should be able to be installed/upgraded successfully.

How Did You Get This To Happen?

  1. Start a Windows 7 with PowerShell 2 VM
  2. Install Chocolatey 1.3.1
  3. Attempt to install a package.

System Details

  • Operating System: Windows 7
  • Windows PowerShell version: 2
  • Chocolatey CLI Version: 1.3.1
  • Chocolatey Licensed Extension version: N/A
  • Chocolatey License type: N/A
  • Terminal/Emulator: ConHost

Installed Packages

Chocolatey 1.3.1

Output Log

2023-03-24 12:37:21,237 3260 [DEBUG] - XmlConfiguration is now operational
2023-03-24 12:37:21,503 3260 [DEBUG] - Adding new type 'WebPiService' for type 'ISourceRunner' from assembly 'choco'
2023-03-24 12:37:21,503 3260 [DEBUG] - Adding new type 'WindowsFeatureService' for type 'ISourceRunner' from assembly 'choco'
2023-03-24 12:37:21,518 3260 [DEBUG] - Adding new type 'CygwinService' for type 'ISourceRunner' from assembly 'choco'
2023-03-24 12:37:21,518 3260 [DEBUG] - Adding new type 'PythonService' for type 'ISourceRunner' from assembly 'choco'
2023-03-24 12:37:21,518 3260 [DEBUG] - Adding new type 'RubyGemsService' for type 'ISourceRunner' from assembly 'choco'
2023-03-24 12:37:21,518 3260 [DEBUG] - Adding new type 'SystemStateValidation' for type 'IValidation' from assembly 'choco'
2023-03-24 12:37:21,784 3260 [DEBUG] - Registering new command 'templates' in assembly 'choco'
2023-03-24 12:37:21,800 3260 [DEBUG] - Registering new command 'upgrade' in assembly 'choco'
2023-03-24 12:37:21,800 3260 [DEBUG] - Registering new command 'export' in assembly 'choco'
2023-03-24 12:37:21,800 3260 [DEBUG] - Registering new command 'list' in assembly 'choco'
2023-03-24 12:37:21,800 3260 [DEBUG] - Registering new command 'info' in assembly 'choco'
2023-03-24 12:37:21,800 3260 [DEBUG] - Registering new command 'help' in assembly 'choco'
2023-03-24 12:37:21,815 3260 [DEBUG] - Registering new command 'config' in assembly 'choco'
2023-03-24 12:37:21,815 3260 [DEBUG] - Registering new command 'feature' in assembly 'choco'
2023-03-24 12:37:21,815 3260 [DEBUG] - Registering new command 'new' in assembly 'choco'
2023-03-24 12:37:21,815 3260 [DEBUG] - Registering new command 'outdated' in assembly 'choco'
2023-03-24 12:37:21,815 3260 [DEBUG] - Registering new command 'pack' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'pin' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'push' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'apikey' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'sources' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'uninstall' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'unpackself' in assembly 'choco'
2023-03-24 12:37:21,831 3260 [DEBUG] - Registering new command 'install' in assembly 'choco'
2023-03-24 12:37:23,862 3260 [INFO ] - ============================================================
2023-03-24 12:37:24,347 3260 [INFO ] - Chocolatey v1.3.0
2023-03-24 12:37:24,378 3260 [DEBUG] - Chocolatey is running on Windows v 6.1.7601.65536
2023-03-24 12:37:24,378 3260 [DEBUG] - Attempting to delete file "C:/ProgramData/chocolatey/choco.exe.old".
2023-03-24 12:37:24,378 3260 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\choco.exe.old".
2023-03-24 12:37:24,409 3260 [DEBUG] - Command line: "C:\ProgramData\chocolatey\choco.exe" install pkg -s .
2023-03-24 12:37:24,409 3260 [DEBUG] - Received arguments: install pkg -s .
2023-03-24 12:37:24,643 3260 [DEBUG] - RemovePendingPackagesTask is now ready and waiting for PreRunMessage.
2023-03-24 12:37:24,659 3260 [WARN ] -  !!WARNING!!
Choco prefers to use TLS v1.2 if it is available, but this client is
 running on .NET 4.0, which uses an older SSL. It's using TLS 1.0 or
 earlier, which makes it susceptible to BEAST and also doesn't
 implement the 1/n-1 record splitting mitigation for Cipher-Block
 Chaining. Upgrade to at least .NET 4.5 at your earliest convenience.

 For more information you should visit https://www.howsmyssl.com/
2023-03-24 12:37:24,690 3260 [DEBUG] - Sending message 'PreRunMessage' out if there are subscribers...
2023-03-24 12:37:24,706 3260 [DEBUG] - [Pending] Removing all pending packages that should not be considered installed...
2023-03-24 12:37:24,878 3260 [DEBUG] - Performing validation checks.
2023-03-24 12:37:24,893 3260 [DEBUG] - Global Configuration Validation Checks:
2023-03-24 12:37:24,893 3260 [DEBUG] -  - Package Exit Code / Exit On Reboot = Checked
2023-03-24 12:37:24,909 3260 [DEBUG] - System State Validation Checks:
2023-03-24 12:37:24,909 3260 [DEBUG] -  Reboot Requirement Checks:
2023-03-24 12:37:24,925 3260 [DEBUG] -  - Pending Computer Rename = Checked
2023-03-24 12:37:24,925 3260 [DEBUG] -  - Pending Component Based Servicing = Checked
2023-03-24 12:37:24,925 3260 [DEBUG] -  - Pending Windows Auto Update = Checked
2023-03-24 12:37:24,925 3260 [DEBUG] -  - Pending File Rename Operations = Ignored
2023-03-24 12:37:24,940 3260 [DEBUG] -  - Pending Windows Package Installer = Checked
2023-03-24 12:37:24,940 3260 [DEBUG] -  - Pending Windows Package Installer SysWow64 = Checked
2023-03-24 12:37:24,956 3260 [INFO ] - 2 validations performed. 2 success(es), 0 warning(s), and 0 error(s).
2023-03-24 12:37:25,003 3260 [DEBUG] - The source '.' evaluated to a 'normal' source type
2023-03-24 12:37:25,003 3260 [DEBUG] - 
NOTE: Hiding sensitive configuration data! Please double and triple
 check to be sure no sensitive data is shown, especially if copying
 output to a gist for review.
2023-03-24 12:37:25,050 3260 [DEBUG] - Configuration: CommandName='install'|CacheLocation='C:\ProgramData\choco-cache'|
ContainsLegacyPackageInstalls='True'|
CommandExecutionTimeoutSeconds='14400'|WebRequestTimeoutSeconds='30'|
Sources='.'|SourceType='normal'|Debug='False'|Verbose='False'|
Trace='False'|Force='False'|Noop='False'|HelpRequested='False'|
UnsuccessfulParsing='False'|RegularOutput='True'|QuietOutput='False'|
PromptForConfirmation='False'|DisableCompatibilityChecks='False'|
AcceptLicense='False'|AllowUnofficialBuild='False'|Input='pkg'|
AllVersions='False'|SkipPackageInstallProvider='False'|
SkipHookScripts='False'|PackageNames='pkg'|Prerelease='False'|
ForceX86='False'|OverrideArguments='False'|NotSilent='False'|
ApplyPackageParametersToDependencies='False'|
ApplyInstallArgumentsToDependencies='False'|IgnoreDependencies='False'|
AllowMultipleVersions='False'|AllowDowngrade='False'|
ForceDependencies='False'|PinPackage='False'|
Information.PlatformType='Windows'|
Information.PlatformVersion='6.1.7601.65536'|
Information.PlatformName='Windows 7'|
Information.ChocolateyVersion='1.3.0.0'|
Information.ChocolateyProductVersion='1.3.0'|
Information.FullName='choco, Version=1.3.0.0, Culture=neutral, PublicKeyToken=79d02ea9cad655eb'|

Information.Is64BitOperatingSystem='True'|
Information.Is64BitProcess='True'|Information.IsInteractive='True'|
Information.UserName='vagrant'|Information.UserDomainName='WINDOWS7'|
Information.IsUserAdministrator='True'|
Information.IsUserSystemAccount='False'|
Information.IsUserRemoteDesktop='False'|
Information.IsUserRemote='False'|Information.IsProcessElevated='True'|
Information.IsLicensedVersion='False'|Information.LicenseType='Foss'|
Information.CurrentDirectory='C:\tmp'|Features.AutoUninstaller='True'|
Features.ChecksumFiles='True'|Features.AllowEmptyChecksums='False'|
Features.AllowEmptyChecksumsSecure='True'|
Features.FailOnAutoUninstaller='False'|
Features.FailOnStandardError='False'|Features.UsePowerShellHost='True'|
Features.LogEnvironmentValues='True'|Features.LogWithoutColor='False'|
Features.VirusCheck='False'|
Features.FailOnInvalidOrMissingLicense='False'|
Features.IgnoreInvalidOptionsSwitches='True'|
Features.UsePackageExitCodes='True'|
Features.UseEnhancedExitCodes='False'|
Features.UseFipsCompliantChecksums='False'|
Features.ShowNonElevatedWarnings='True'|
Features.ShowDownloadProgress='True'|
Features.StopOnFirstPackageFailure='False'|
Features.UseRememberedArgumentsForUpgrades='False'|
Features.IgnoreUnfoundPackagesOnUpgradeOutdated='False'|
Features.SkipPackageUpgradesWhenNotInstalled='False'|
Features.RemovePackageInformationOnUninstall='False'|
Features.ExitOnRebootDetected='False'|
Features.LogValidationResultsOnWarnings='True'|
Features.UsePackageRepositoryOptimizations='True'|
ListCommand.LocalOnly='False'|ListCommand.IdOnly='False'|
ListCommand.IncludeRegistryPrograms='False'|ListCommand.PageSize='25'|
ListCommand.Exact='False'|ListCommand.ByIdOnly='False'|
ListCommand.ByTagOnly='False'|ListCommand.IdStartsWith='False'|
ListCommand.OrderByPopularity='False'|ListCommand.ApprovedOnly='False'|
ListCommand.DownloadCacheAvailable='False'|
ListCommand.NotBroken='False'|
ListCommand.IncludeVersionOverrides='False'|
UpgradeCommand.FailOnUnfound='False'|
UpgradeCommand.FailOnNotInstalled='False'|
UpgradeCommand.NotifyOnlyAvailableUpgrades='False'|
UpgradeCommand.ExcludePrerelease='False'|
NewCommand.AutomaticPackage='False'|
NewCommand.UseOriginalTemplate='False'|SourceCommand.Command='unknown'|
SourceCommand.Priority='0'|SourceCommand.BypassProxy='False'|
SourceCommand.AllowSelfService='False'|
SourceCommand.VisibleToAdminsOnly='False'|
FeatureCommand.Command='unknown'|ConfigCommand.Command='unknown'|
ApiKeyCommand.Remove='False'|PinCommand.Command='unknown'|
OutdatedCommand.IgnorePinned='False'|
ExportCommand.IncludeVersionNumbers='False'|Proxy.BypassOnLocal='True'|
TemplateCommand.Command='unknown'|
2023-03-24 12:37:25,050 3260 [DEBUG] - _ Chocolatey:ChocolateyInstallCommand - Normal Run Mode _
2023-03-24 12:37:25,065 3260 [INFO ] - Installing the following packages:
2023-03-24 12:37:25,081 3260 [INFO ] - pkg
2023-03-24 12:37:25,081 3260 [INFO ] - By installing, you accept licenses for the packages.
2023-03-24 12:37:25,112 3260 [DEBUG] - Current environment values (may contain sensitive data):
2023-03-24 12:37:25,112 3260 [DEBUG] -   * 'TEMP'='C:\Users\vagrant\AppData\Local\Temp' ('User')
2023-03-24 12:37:25,112 3260 [DEBUG] -   * 'TMP'='C:\Users\vagrant\AppData\Local\Temp' ('User')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'ChocolateyLastPathUpdate'='133241594414236340' ('User')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'trigger'='1' ('User')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'ComSpec'='C:\Windows\system32\cmd.exe' ('Machine')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'FP_NO_HOST_CHECK'='NO' ('Machine')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'OS'='Windows_NT' ('Machine')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'Path'='C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;' ('Machine')
2023-03-24 12:37:25,128 3260 [DEBUG] -   * 'PATHEXT'='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'PROCESSOR_ARCHITECTURE'='AMD64' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'TEMP'='C:\Windows\TEMP' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'TMP'='C:\Windows\TEMP' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'USERNAME'='SYSTEM' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'windir'='C:\Windows' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'PSModulePath'='C:\Windows\system32\WindowsPowerShell\v1.0\Modules\' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'NUMBER_OF_PROCESSORS'='4' ('Machine')
2023-03-24 12:37:25,143 3260 [DEBUG] -   * 'PROCESSOR_LEVEL'='6' ('Machine')
2023-03-24 12:37:25,159 3260 [DEBUG] -   * 'PROCESSOR_IDENTIFIER'='Intel64 Family 6 Model 158 Stepping 13, GenuineIntel' ('Machine')
2023-03-24 12:37:25,159 3260 [DEBUG] -   * 'PROCESSOR_REVISION'='9e0d' ('Machine')
2023-03-24 12:37:25,159 3260 [DEBUG] -   * 'windows_tracing_logfile'='C:\BVTBin\Tests\installpackage\csilogfile.log' ('Machine')
2023-03-24 12:37:25,159 3260 [DEBUG] -   * 'windows_tracing_flags'='3' ('Machine')
2023-03-24 12:37:25,159 3260 [DEBUG] -   * 'ChocolateyInstall'='C:\ProgramData\chocolatey' ('Machine')
2023-03-24 12:37:25,487 3260 [DEBUG] - Using '.'.
2023-03-24 12:37:25,487 3260 [DEBUG] - - Supports prereleases? 'True'.
2023-03-24 12:37:25,487 3260 [DEBUG] - - Is ServiceBased? 'False'.
2023-03-24 12:37:26,237 3260 [DEBUG] - Package 'pkg' found on source '.'
2023-03-24 12:37:26,768 3260 [INFO ] - [NuGet] Installing 'pkg 1.0.0'.
2023-03-24 12:37:26,784 3260 [DEBUG] - [NuGet] Added file 'chocolateyinstall.ps1' to folder 'pkg\tools'.
2023-03-24 12:37:26,784 3260 [DEBUG] - [NuGet] Added file 'LICENSE.txt' to folder 'pkg\tools'.
2023-03-24 12:37:26,784 3260 [DEBUG] - [NuGet] Added file 'VERIFICATION.txt' to folder 'pkg\tools'.
2023-03-24 12:37:26,800 3260 [DEBUG] - [NuGet] Added file 'pkg.nupkg' to folder 'pkg'.
2023-03-24 12:37:27,393 3260 [DEBUG] - [NuGet] Added file 'pkg.nuspec' to folder 'pkg'.
2023-03-24 12:37:27,409 3260 [INFO ] - [NuGet] Successfully installed 'pkg 1.0.0'.
2023-03-24 12:37:27,409 3260 [INFO ] - 
pkg v1.0.0
2023-03-24 12:37:27,472 3260 [INFO ] - pkg package files install completed. Performing other installation steps.
2023-03-24 12:37:27,831 3260 [DEBUG] - Setting installer args for pkg
2023-03-24 12:37:27,831 3260 [DEBUG] - Setting package parameters for pkg
2023-03-24 12:37:27,831 3260 [DEBUG] - Contents of 'C:\ProgramData\chocolatey\lib\pkg\tools\chocolateyinstall.ps1':
2023-03-24 12:37:27,831 3260 [DEBUG] - 
2023-03-24 12:37:27,878 3260 [DEBUG] - Calling built-in PowerShell host 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\pkg\tools\chocolateyinstall.ps1' -installArguments '' -packageParameters '' -preRunHookScripts $null -postRunHookScripts $null']
2023-03-24 12:37:27,925 3260 [DEBUG] - Redirecting System.Management.Automation.resources, Version=1.0.0.0, Culture=en-US, PublicKeyToken=31bf3856ad364e35, requested by ''
2023-03-24 12:37:31,909 3260 [DEBUG] - Host version is 2.0, PowerShell Version is '2.0' and CLR Version is '4.0.30319.1'.
2023-03-24 12:37:32,503 3260 [INFO ] - VERBOSE: Exporting function 'Format-FileSize'.
2023-03-24 12:37:32,503 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChecksumValid'.
2023-03-24 12:37:32,503 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChocolateyPath'.
2023-03-24 12:37:32,503 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChocolateyUnzip'.
2023-03-24 12:37:32,503 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChocolateyWebFile'.
2023-03-24 12:37:32,503 3260 [INFO ] - VERBOSE: Exporting function 'Get-EnvironmentVariable'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-EnvironmentVariableNames'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-FtpFile'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-OSArchitectureWidth'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-PackageParameters'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-PackageParametersBuiltIn'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-ToolsLocation'.
2023-03-24 12:37:32,518 3260 [INFO ] - VERBOSE: Exporting function 'Get-UACEnabled'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Get-UninstallRegistryKey'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Get-VirusCheckValid'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Get-WebFile'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Get-WebFileName'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Get-WebHeaders'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Install-BinFile'.
2023-03-24 12:37:32,534 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyEnvironmentVariable'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyExplorerMenuItem'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyFileAssociation'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyInstallPackage'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPackage'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPath'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPinnedTaskBarItem'.
2023-03-24 12:37:32,550 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPowershellCommand'.
2023-03-24 12:37:32,565 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyShortcut'.
2023-03-24 12:37:32,565 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyVsixPackage'.
2023-03-24 12:37:32,565 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyZipPackage'.
2023-03-24 12:37:32,565 3260 [INFO ] - VERBOSE: Exporting function 'Install-Vsix'.
2023-03-24 12:37:32,565 3260 [INFO ] - VERBOSE: Exporting function 'Set-EnvironmentVariable'.
2023-03-24 12:37:32,565 3260 [INFO ] - VERBOSE: Exporting function 'Set-PowerShellExitCode'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Start-ChocolateyProcessAsAdmin'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Test-ProcessAdminRights'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-BinFile'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-ChocolateyEnvironmentVariable'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-ChocolateyPackage'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-ChocolateyZipPackage'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Update-SessionEnvironment'.
2023-03-24 12:37:32,581 3260 [INFO ] - VERBOSE: Exporting function 'Write-FunctionCallLogMessage'.
2023-03-24 12:37:32,597 3260 [INFO ] - VERBOSE: Exporting alias 'Get-ProcessorBits'.
2023-03-24 12:37:32,597 3260 [INFO ] - VERBOSE: Exporting alias 'Get-OSBitness'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'Get-InstallRegistryKey'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'Generate-BinFile'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'Add-BinFile'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'Start-ChocolateyProcess'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'Invoke-ChocolateyProcess'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'Remove-BinFile'.
2023-03-24 12:37:32,612 3260 [INFO ] - VERBOSE: Exporting alias 'refreshenv'.
2023-03-24 12:37:32,643 3260 [INFO ] - VERBOSE: Exporting function 'Format-FileSize'.
2023-03-24 12:37:32,643 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChecksumValid'.
2023-03-24 12:37:32,643 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChocolateyPath'.
2023-03-24 12:37:32,643 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChocolateyUnzip'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-ChocolateyWebFile'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-EnvironmentVariable'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-EnvironmentVariableNames'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-FtpFile'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-OSArchitectureWidth'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-PackageParameters'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-PackageParametersBuiltIn'.
2023-03-24 12:37:32,659 3260 [INFO ] - VERBOSE: Exporting function 'Get-ToolsLocation'.
2023-03-24 12:37:32,675 3260 [INFO ] - VERBOSE: Exporting function 'Get-UACEnabled'.
2023-03-24 12:37:32,675 3260 [INFO ] - VERBOSE: Exporting function 'Get-UninstallRegistryKey'.
2023-03-24 12:37:32,675 3260 [INFO ] - VERBOSE: Exporting function 'Get-VirusCheckValid'.
2023-03-24 12:37:32,675 3260 [INFO ] - VERBOSE: Exporting function 'Get-WebFile'.
2023-03-24 12:37:32,675 3260 [INFO ] - VERBOSE: Exporting function 'Get-WebFileName'.
2023-03-24 12:37:32,675 3260 [INFO ] - VERBOSE: Exporting function 'Get-WebHeaders'.
2023-03-24 12:37:32,690 3260 [INFO ] - VERBOSE: Exporting function 'Install-BinFile'.
2023-03-24 12:37:32,690 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyEnvironmentVariable'.
2023-03-24 12:37:32,690 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyExplorerMenuItem'.
2023-03-24 12:37:32,690 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyFileAssociation'.
2023-03-24 12:37:32,690 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyInstallPackage'.
2023-03-24 12:37:32,690 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPackage'.
2023-03-24 12:37:32,706 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPath'.
2023-03-24 12:37:32,706 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPinnedTaskBarItem'.
2023-03-24 12:37:32,706 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyPowershellCommand'.
2023-03-24 12:37:32,706 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyShortcut'.
2023-03-24 12:37:32,706 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyVsixPackage'.
2023-03-24 12:37:32,706 3260 [INFO ] - VERBOSE: Exporting function 'Install-ChocolateyZipPackage'.
2023-03-24 12:37:32,722 3260 [INFO ] - VERBOSE: Exporting function 'Install-Vsix'.
2023-03-24 12:37:32,722 3260 [INFO ] - VERBOSE: Exporting function 'Set-EnvironmentVariable'.
2023-03-24 12:37:32,722 3260 [INFO ] - VERBOSE: Exporting function 'Set-PowerShellExitCode'.
2023-03-24 12:37:32,722 3260 [INFO ] - VERBOSE: Exporting function 'Start-ChocolateyProcessAsAdmin'.
2023-03-24 12:37:32,722 3260 [INFO ] - VERBOSE: Exporting function 'Test-ProcessAdminRights'.
2023-03-24 12:37:32,722 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-BinFile'.
2023-03-24 12:37:32,737 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-ChocolateyEnvironmentVariable'.
2023-03-24 12:37:32,737 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-ChocolateyPackage'.
2023-03-24 12:37:32,737 3260 [INFO ] - VERBOSE: Exporting function 'Uninstall-ChocolateyZipPackage'.
2023-03-24 12:37:32,737 3260 [INFO ] - VERBOSE: Exporting function 'Update-SessionEnvironment'.
2023-03-24 12:37:32,737 3260 [INFO ] - VERBOSE: Exporting function 'Write-FunctionCallLogMessage'.
2023-03-24 12:37:32,737 3260 [INFO ] - VERBOSE: Exporting alias 'Get-ProcessorBits'.
2023-03-24 12:37:32,753 3260 [INFO ] - VERBOSE: Exporting alias 'Get-OSBitness'.
2023-03-24 12:37:32,753 3260 [INFO ] - VERBOSE: Exporting alias 'Get-InstallRegistryKey'.
2023-03-24 12:37:32,753 3260 [INFO ] - VERBOSE: Exporting alias 'Generate-BinFile'.
2023-03-24 12:37:32,753 3260 [INFO ] - VERBOSE: Exporting alias 'Add-BinFile'.
2023-03-24 12:37:32,753 3260 [INFO ] - VERBOSE: Exporting alias 'Start-ChocolateyProcess'.
2023-03-24 12:37:33,175 3260 [INFO ] - VERBOSE: Exporting alias 'Invoke-ChocolateyProcess'.
2023-03-24 12:37:33,175 3260 [INFO ] - VERBOSE: Exporting alias 'Remove-BinFile'.
2023-03-24 12:37:33,175 3260 [INFO ] - VERBOSE: Exporting alias 'refreshenv'.
2023-03-24 12:37:33,253 3260 [INFO ] - VERBOSE: Importing function 'Format-FileSize'.
2023-03-24 12:37:33,253 3260 [INFO ] - VERBOSE: Importing function 'Get-ChecksumValid'.
2023-03-24 12:37:33,253 3260 [INFO ] - VERBOSE: Importing function 'Get-ChocolateyPath'.
2023-03-24 12:37:33,253 3260 [INFO ] - VERBOSE: Importing function 'Get-ChocolateyUnzip'.
2023-03-24 12:37:33,253 3260 [INFO ] - VERBOSE: Importing function 'Get-ChocolateyWebFile'.
2023-03-24 12:37:33,268 3260 [INFO ] - VERBOSE: Importing function 'Get-EnvironmentVariable'.
2023-03-24 12:37:33,268 3260 [INFO ] - VERBOSE: Importing function 'Get-EnvironmentVariableNames'.
2023-03-24 12:37:33,268 3260 [INFO ] - VERBOSE: Importing function 'Get-FtpFile'.
2023-03-24 12:37:33,284 3260 [INFO ] - VERBOSE: Importing function 'Get-OSArchitectureWidth'.
2023-03-24 12:37:33,284 3260 [INFO ] - VERBOSE: Importing function 'Get-PackageParameters'.
2023-03-24 12:37:33,284 3260 [INFO ] - VERBOSE: Importing function 'Get-PackageParametersBuiltIn'.
2023-03-24 12:37:33,300 3260 [INFO ] - VERBOSE: Importing function 'Get-ToolsLocation'.
2023-03-24 12:37:33,300 3260 [INFO ] - VERBOSE: Importing function 'Get-UACEnabled'.
2023-03-24 12:37:33,300 3260 [INFO ] - VERBOSE: Importing function 'Get-UninstallRegistryKey'.
2023-03-24 12:37:33,300 3260 [INFO ] - VERBOSE: Importing function 'Get-VirusCheckValid'.
2023-03-24 12:37:33,300 3260 [INFO ] - VERBOSE: Importing function 'Get-WebFile'.
2023-03-24 12:37:33,315 3260 [INFO ] - VERBOSE: Importing function 'Get-WebFileName'.
2023-03-24 12:37:33,315 3260 [INFO ] - VERBOSE: Importing function 'Get-WebHeaders'.
2023-03-24 12:37:33,315 3260 [INFO ] - VERBOSE: Importing function 'Install-BinFile'.
2023-03-24 12:37:33,315 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyEnvironmentVariable'.
2023-03-24 12:37:33,315 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyExplorerMenuItem'.
2023-03-24 12:37:33,315 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyFileAssociation'.
2023-03-24 12:37:33,331 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyInstallPackage'.
2023-03-24 12:37:33,331 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyPackage'.
2023-03-24 12:37:33,347 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyPath'.
2023-03-24 12:37:33,347 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyPinnedTaskBarItem'.
2023-03-24 12:37:33,347 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyPowershellCommand'.
2023-03-24 12:37:33,347 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyShortcut'.
2023-03-24 12:37:33,362 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyVsixPackage'.
2023-03-24 12:37:33,362 3260 [INFO ] - VERBOSE: Importing function 'Install-ChocolateyZipPackage'.
2023-03-24 12:37:33,378 3260 [INFO ] - VERBOSE: Importing function 'Install-Vsix'.
2023-03-24 12:37:33,393 3260 [INFO ] - VERBOSE: Importing function 'Set-EnvironmentVariable'.
2023-03-24 12:37:33,409 3260 [INFO ] - VERBOSE: Importing function 'Set-PowerShellExitCode'.
2023-03-24 12:37:33,409 3260 [INFO ] - VERBOSE: Importing function 'Start-ChocolateyProcessAsAdmin'.
2023-03-24 12:37:33,409 3260 [INFO ] - VERBOSE: Importing function 'Test-ProcessAdminRights'.
2023-03-24 12:37:33,425 3260 [INFO ] - VERBOSE: Importing function 'Uninstall-BinFile'.
2023-03-24 12:37:33,440 3260 [INFO ] - VERBOSE: Importing function 'Uninstall-ChocolateyEnvironmentVariable'.
2023-03-24 12:37:33,440 3260 [INFO ] - VERBOSE: Importing function 'Uninstall-ChocolateyPackage'.
2023-03-24 12:37:33,440 3260 [INFO ] - VERBOSE: Importing function 'Uninstall-ChocolateyZipPackage'.
2023-03-24 12:37:33,440 3260 [INFO ] - VERBOSE: Importing function 'Update-SessionEnvironment'.
2023-03-24 12:37:33,440 3260 [INFO ] - VERBOSE: Importing function 'Write-FunctionCallLogMessage'.
2023-03-24 12:37:33,456 3260 [INFO ] - VERBOSE: Importing alias 'Add-BinFile'.
2023-03-24 12:37:33,456 3260 [INFO ] - VERBOSE: Importing alias 'Generate-BinFile'.
2023-03-24 12:37:33,472 3260 [INFO ] - VERBOSE: Importing alias 'Get-InstallRegistryKey'.
2023-03-24 12:37:33,472 3260 [INFO ] - VERBOSE: Importing alias 'Get-OSBitness'.
2023-03-24 12:37:33,472 3260 [INFO ] - VERBOSE: Importing alias 'Get-ProcessorBits'.
2023-03-24 12:37:33,472 3260 [INFO ] - VERBOSE: Importing alias 'Invoke-ChocolateyProcess'.
2023-03-24 12:37:33,472 3260 [INFO ] - VERBOSE: Importing alias 'refreshenv'.
2023-03-24 12:37:33,487 3260 [INFO ] - VERBOSE: Importing alias 'Remove-BinFile'.
2023-03-24 12:37:33,487 3260 [INFO ] - VERBOSE: Importing alias 'Start-ChocolateyProcess'.
2023-03-24 12:37:33,518 3260 [DEBUG] - ---------------------------Script Execution---------------------------
2023-03-24 12:37:33,518 3260 [DEBUG] - Running 'ChocolateyScriptRunner' for pkg v1.0.0 with packageScript 'C:\ProgramData\chocolatey\lib\pkg\tools\chocolateyinstall.ps1', packageFolder:'C:\ProgramData\chocolatey\lib\pkg', installArguments: '', packageParameters: '', preRunHookScripts: '', postRunHookScripts: '',
2023-03-24 12:37:33,534 3260 [DEBUG] - Running Pre-Run Hook ''
2023-03-24 12:37:33,565 3260 [ERROR] - ERROR: The expression after '&' in a pipeline element produced an invalid object. It must result in a command name, script block or CommandInfo object.
2023-03-24 12:37:33,612 3260 [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\pkg\tools\chocolateyinstall.ps1' -installArguments '' -packageParameters '' -preRunHookScripts $null -postRunHookScripts $null'] exited with '-1'.
2023-03-24 12:37:33,628 3260 [DEBUG] - Calling command ['"C:\Windows\System32\shutdown.exe" /a']
2023-03-24 12:37:33,690 3260 [DEBUG] - Command ['"C:\Windows\System32\shutdown.exe" /a'] exited with '1116'
2023-03-24 12:37:35,284 3260 [DEBUG] - Capturing package files in 'C:\ProgramData\chocolatey\lib\pkg'
2023-03-24 12:37:35,284 3260 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\pkg\pkg.nupkg'
  with checksum '5EC98C108E02C29B94AB6C04D896CF4A'
2023-03-24 12:37:35,300 3260 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\pkg\pkg.nuspec'
  with checksum '14FB632592B74875011A7C488D64CF26'
2023-03-24 12:37:35,300 3260 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\pkg\tools\chocolateyinstall.ps1'
  with checksum 'D41D8CD98F00B204E9800998ECF8427E'
2023-03-24 12:37:35,300 3260 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\pkg\tools\LICENSE.txt'
  with checksum '70EF4B693AB3129285C4259271F0CEA6'
2023-03-24 12:37:35,300 3260 [DEBUG] -  Found 'C:\ProgramData\chocolatey\lib\pkg\tools\VERIFICATION.txt'
  with checksum '4BF3ED9013EC8FB026E91EAB15C8C2C8'
2023-03-24 12:37:35,362 3260 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\pkg.1.0.0\.arguments".
2023-03-24 12:37:35,378 3260 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\pkg.1.0.0\.extra".
2023-03-24 12:37:35,378 3260 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\pkg.1.0.0\.version".
2023-03-24 12:37:35,378 3260 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\pkg.1.0.0\.sxs".
2023-03-24 12:37:35,393 3260 [DEBUG] - Attempting to delete file "C:\ProgramData\chocolatey\.chocolatey\pkg.1.0.0\.pin".
2023-03-24 12:37:35,409 3260 [DEBUG] - Attempting to delete directory "C:\ProgramData\chocolatey\lib-bad\pkg".
2023-03-24 12:37:35,440 3260 [DEBUG] - Sending message 'HandlePackageResultCompletedMessage' out if there are subscribers...
2023-03-24 12:37:35,440 3260 [ERROR] - The install of pkg was NOT successful.
2023-03-24 12:37:35,472 3260 [ERROR] - Error while running 'C:\ProgramData\chocolatey\lib\pkg\tools\chocolateyinstall.ps1'.
 See log for details.
2023-03-24 12:37:35,487 3260 [DEBUG] - Moving 'C:\ProgramData\chocolatey\lib\pkg'
 to 'C:\ProgramData\chocolatey\lib-bad\pkg'
2023-03-24 12:37:37,518 3260 [WARN ] - 
Chocolatey installed 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
2023-03-24 12:37:37,534 3260 [INFO ] - 
2023-03-24 12:37:37,534 3260 [ERROR] - Failures
2023-03-24 12:37:37,550 3260 [ERROR] -  - pkg (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\pkg\tools\chocolateyinstall.ps1'.
 See log for details.
2023-03-24 12:37:37,565 3260 [DEBUG] - Sending message 'PostRunMessage' out if there are subscribers...
2023-03-24 12:37:37,597 3260 [DEBUG] - Exiting with -1

Additional Context

No response

@mymaestro
Copy link

You can reproduce this in Windows 10 by enabling the PowerShellV2 feature (in an elevated shell):
Enable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2

@corbob
Copy link
Member Author

corbob commented Mar 24, 2023

You can reproduce this in Windows 10 by enabling the PowerShellV2 feature (in an elevated shell):
Enable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2

I really wish it was as simple as this. I have not been able to reproduce even when launching chocolatey from PowerShell 2 on Windows 10.

image

@hhonisch
Copy link

The issue is caused by the PowerShell feature "ForEach statement does not iterate over $null" introduced in PS v3 (see https://devblogs.microsoft.com/powershell/new-v3-language-features/).

This causes the code in chocolateyScriptRunner.ps1 which runs the hook scripts to behave differently depending on whether it's executed in PS v2 or PS v3.
More precisely, in PS v2 it tries to call the hook script "$null" if there are no hook scripts defined, which obviously makes no sense and causes the error. See the log entry "Running Pre-Run Hook ''" above.
In PS v3 this does not happen.

See this code in chocolateyScriptRunner.ps1 (comments added by me):

param(
  # ...
  [string[]]$preRunHookScripts,   # set to $null when there are not hook scripts
  [string[]]$postRunHookScripts   # set to $null when there are not hook scripts 
)
#... 
if ($PSBoundParameters.ContainsKey('preRunHookScripts')) {          # <- evaluates to $true, even when $preRunHookScripts is $null
    foreach ($prehookscript in $preRunHookScripts) {                # PS v2: "foreach" iterates over "$null" / PS v3: "foreach" does NOT iterate over "$null"
        Write-Debug "Running Pre-Run Hook '$prehookscript'";        # PS v2: Code performs one loop iteration with "$prehookscript" set to "$null"
        & "$prehookscript"                                          # PS v2: Calling the script "$null" fails
    }
}
#... 
if ($PSBoundParameters.ContainsKey('postRunHookScripts')) {         # Same here
    foreach ($posthookscript in $postRunHookScripts) {
        Write-Debug "Running Post-Run Hook '$posthookscript'";
        & "$posthookscript"
    }
}

To fix the issue, I suggest to explicitly check for $null before iterating over "$preRunHookScripts)" or "$postRunHookScripts". for example:

if ($PSBoundParameters.ContainsKey('preRunHookScripts') -and ($preRunHookScripts -ne $null)) {
    # ...
}
# ...
if ($PSBoundParameters.ContainsKey('postRunHookScripts') -and ($postRunHookScripts -ne $null)) {
    # ...
}

I've tested the fix in a Windows 7 / PS v2 enviroment, it works as expected

@corbob
Copy link
Member Author

corbob commented Mar 26, 2023

@hhonisch thank you for that information. I knew it was a change in behaviour of PowerShell v3, but couldn't find the post about the change.

To bring some information that @mymaestro provided in the reddit thread, and in order to try to keep the information up to date in the issue here now that we have it, here is interesting and relevant information from the reddit thread:

2023-03-18 13:37:32,597 19832 [DEBUG] - Calling built-in PowerShell host 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\GoogleChrome\tools\chocolateyInstall.ps1' -installArguments '' -packageParameters '' -preRunHookScripts $null -postRunHookScripts $null']
2023-03-18 13:37:32,620 19832 [DEBUG] - Redirecting System.Management.Automation.resources, Version=1.0.0.0, Culture=en-US, PublicKeyToken=31bf3856ad364e35, requested by ''
2023-03-18 13:37:33,707 19832 [DEBUG] - Host version is 5.1.21390.1, PowerShell Version is '2.0' and CLR Version is '4.0.30319.42000'.

The part that I find interesting is that the Host version is correctly detecting that it's Windows 10, but the PowerShell version is dropping to 2.0 which is something that I cannot reproduce. However, when I try to find information on this particular build (21390.2025), it all seems to point to it being an insider build from mid 2021. Which might suggest a bugged Insider build that has since been fixed.

I have a fix that is very similar to what @hhonisch suggested, but just forgoes both the PSBoundParameters check and the null check. I'll get it updated and pushed up, but likely won't make it into Chocolatey until 2.0.0 is released. Will also be adding some pester tests to ensure we don't regress on this, and more properly test the chocolateyScriptRunner script.

@corbob corbob self-assigned this Mar 27, 2023
corbob added a commit to corbob/choco that referenced this issue Mar 27, 2023
corbob added a commit to corbob/choco that referenced this issue Mar 27, 2023
PowerShell 2 had the behaviour that foreach would iterate over a null
variable
(https://devblogs.microsoft.com/powershell/new-v3-language-features/).
This has resulted in an issue if no hook scripts are passed in, then
chocolateyScriptRunner would cause an error. This update changes this to
do a nullcheck like we already had for the packageScript parameter.
corbob added a commit to corbob/choco that referenced this issue Mar 27, 2023
PowerShell 2 had the behaviour that foreach would iterate over a null
variable
(https://devblogs.microsoft.com/powershell/new-v3-language-features/).
This has resulted in an issue if no hook scripts are passed in, then
chocolateyScriptRunner would cause an error. This update changes this to
do a nullcheck like we already had for the packageScript parameter.
corbob added a commit to corbob/choco that referenced this issue Mar 27, 2023
PowerShell 2 had the behaviour that foreach would iterate over a null
variable
(https://devblogs.microsoft.com/powershell/new-v3-language-features/).
This has resulted in an issue if no hook scripts are passed in, then
chocolateyScriptRunner would cause an error. This update changes this to
do a nullcheck like we already had for the packageScript parameter.
@gep13 gep13 added this to the 2.0.0 milestone Apr 5, 2023
gep13 pushed a commit to corbob/choco that referenced this issue Apr 5, 2023
PowerShell 2 had the behaviour that foreach would iterate over a null
variable
(https://devblogs.microsoft.com/powershell/new-v3-language-features/).
This has resulted in an issue if no hook scripts are passed in, then
chocolateyScriptRunner would cause an error. This update changes this to
do a nullcheck like we already had for the packageScript parameter.
@pauby
Copy link
Member

pauby commented Apr 5, 2023

Linked to #865c2w28t

gep13 pushed a commit to corbob/choco that referenced this issue Apr 5, 2023
PowerShell 2 had the behaviour that foreach would iterate over a null
variable
(https://devblogs.microsoft.com/powershell/new-v3-language-features/).
This has resulted in an issue if no hook scripts are passed in, then
chocolateyScriptRunner would cause an error. This update changes this to
do a nullcheck like we already had for the packageScript parameter.
@gep13 gep13 added 4 - Done and removed 3 - Review labels Apr 12, 2023
@gep13 gep13 closed this as completed Apr 12, 2023
@gep13 gep13 changed the title When there are no hook scripts, you cannot install/upgrade on a system with just PowerShell 2 When no hook scripts and installed you cannot install/upgrade a package on a system using PowerShell 2 Apr 12, 2023
@gep13 gep13 modified the milestones: 2.0.0, 1.4.0 May 9, 2023
gep13 pushed a commit that referenced this issue May 9, 2023
PowerShell 2 had the behaviour that foreach would iterate over a null
variable
(https://devblogs.microsoft.com/powershell/new-v3-language-features/).
This has resulted in an issue if no hook scripts are passed in, then
chocolateyScriptRunner would cause an error. This update changes this to
do a nullcheck like we already had for the packageScript parameter.
@gep13 gep13 changed the title When no hook scripts and installed you cannot install/upgrade a package on a system using PowerShell 2 When no hook scripts are installed you cannot install/upgrade a package on a system using PowerShell 2 May 10, 2023
@choco-bot
Copy link

🎉 This issue has been resolved in version 1.4.0 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

@zandadoum
Copy link

This issue has been resolved in version 1.4.0

how can i update version 1.2 to 1.4? because 1.2 gives me the error.

@corbob
Copy link
Member Author

corbob commented May 18, 2023

Hi @zandadoum, that is an excellent question. I have tested the two following methods with success:

  1. Create empty hooks for pre and post install, then run choco upgrade chocolatey.
    a. You should be able to do this with the command: New-Item '$env:ChocolateyInstall\hooks\pre-install-all.ps1', '$env:ChocolateyInstall\hooks\post-install-all.ps1' -Force
  2. Download the chocolatey 1.4.0 nupkg from Chocolatey Community Repository, extract the nupkg to a location, then run the chocolateyinstall.ps1 file from the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants