Chocolatey on Windows 7: “You must provide a value expression on the right-hand side of the ‘-‘ operator.”
Posted by jpluimers on 2022/06/08
One of the places explaining a more and more frequent error on Windows 7 installations is [Wayback/Archive.is] “You must provide a value expression on the right-hand side of the ‘-‘ operator.” · Issue #29 · shiftkey/chocolatey-beyondcompare:
- [Wayback] michaelray:
This error occurs when using PowerShell < v3. The
-in
operator was added in PSv3 and this is the error you would get when trying to use -in with previous versions of PS.To remain compatible with PSv2, use
-contains
instead and swap the operands.…
Here is a link to info on this:
http://www.computerperformance.co.uk/powershell/powershell3-notin.htm#Troubleshooting_PowerShell_-In_and_-NotIn- [Wayback] CADbloke:
ah, thanks for the explains. My fix on Windows 7 …
choco install -y powershell -force
- [Wayback] flcdrg:
FYI Chocolatey currently requires scripts are PowerShell v3 compatible.
Some Powershell packages or core parts fix this, like [Wayback/Archive.is] Packages failing to install/upgrade due to chocolatey-core.psm1 · Issue #1373 · chocolatey-community/chocolatey-coreteampackages
- [Wayback] majkinetor:
Nice catch @AdmiringWorm
More and more packages do not fix this because of the above mentioned minimum requirement being PowerShell v3 (and likely Windows 7 officially not being supported anymore). It is odd, as these are the [Wayback] Chocolatey Software Docs | Setup / Install: Requirements
- Windows 7+ / Windows Server 2003+
- PowerShell v2+ (Not PowerShell Core yet though)(minimum is v3 for install from this website due to TLS 1.2 requirement)
- .NET Framework 4+ (the installation will attempt to install .NET 4.0 if you do not have it installed)(minimum is 4.5 for install from this website due to TLS 1.2 requirement)
That’s it! All you need is choco.exe (that you get from the installation scripts) and you are good to go! No Visual Studio required.
So it is best to update your Windows 7 systems to PowerShell version 3. You’d think that would be as straightforward as installing the most recent PowerShell 3.x version, which is in [Wayback] Chocolatey Software | Windows Management Framework and PowerShell 3.0 3.0.20121027, but it isn’t that easy:
C:\>choco upgrade --yes powershell --version=3.0.20121027 Chocolatey v0.11.1 Upgrading the following packages: powershell By upgrading, you accept licenses for the packages. powershell is not installed. Installing... Progress: Downloading PowerShell 3.0.20121027... 100% Progress: Downloading PowerShell 3.0.20121027... 100% PowerShell v3.0.20121027 powershell package files upgrade completed. Performing other installation steps. You must provide a value expression on the right-hand side of the '-' operator. The specified module 'C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1' was not loaded because no valid module file was found in any module directory. PowerShell 3.0(RTM) ERROR: The term 'Write-ChocolateyFailure' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. The upgrade of powershell was NOT successful. Error while running 'C:\ProgramData\chocolatey\lib\PowerShell\ChocolateyInstall.ps1'. See log for details. Chocolatey upgraded 0/1 packages. 1 packages failed. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). Failures - powershell (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\PowerShell\ChocolateyInstall.ps1'. See log for details.
At the time of writing, there still was no response 2 months after filing [Wayback/Archive] Windows 7 SP1 with PowerShell v2 cannot upgrade to PowerShell v3 (#101) · Issues · DarwinJS / ChocoPackages · GitLab.
More on PowerShell version 3:
- PowerShell: Windows PowerShell 3.0 – Wikipedia
PowerShell 3.0 is integrated with Windows 8 and with Windows Server 2012. Microsoft has also made PowerShell 3.0 available for Windows 7 with Service Pack 1, for Windows Server 2008 with Service Pack 1, and for Windows Server 2008 R2 with Service Pack 1.
PowerShell 3.0 is part of a larger package, Windows Management Framework 3.0 (WMF3), which also contains the WinRM service to support remoting.
- [Wayback] PowerShell 3.0 -NotIn and -In | New Comparator Feature
TROUBLESHOOTING POWERSHELL -IN AND -NOTIN
Incorrect version of PowerShell
You must provide a value expression on the right-hand side of the '-' operator. At line:2 char:6 Unexpected token ‘in’ in expression or statement.
This is what you get in PowerShell 1.0 or 2.0,
-In
is new in PowerShell 3.0Dottiness
You get the ‘wrong’ result, ‘False’ when all logic tells you it should be true. Check you have two ranging dots .. and not three … dots. Strange but true!
Leave a Reply