Comments (5)
@pauby I've made the changes you suggested, and the installation works as expected. Thanks a lot!
from choco.
I'm unsure if --use-system-powershell will use PowerShell Core if it's installed.
It will not use PowerShell Core, it will only use Windows PowerShell (via powershell.exe
) when using system powershell.
Is there a way to force choco use a specific PowerShell version?
In this case, I think the best option would be to call pwsh.exe
in chocolateyInstall.ps1
for any specific commands that need to be run in PowerShell Core. Use Start-ChocolateyProcessAsAdmin
if the command needs administrator privileges.
from choco.
The issue with the package appears to be this line:
if ($PSVersionTable.PSVersion -lt [version]$minPSVersion) {
throw "$moduleName module requires a minimum of PowerShell v$minPSVersion."
}
You're trying to detect the version of the PowerShell host and if it doesn't meet your minimum requirements, throwing an error. However, PowerShell (Core) is an optional install, on the majority of operating systems. But that doesn't stop your package from being installed. Your package doesn't need PowerShell Core. The module Okta.PowerShell
does. But you're not running the module in the package. The package is simply the deployment method, so it doesn't matter what version of PowerShell it uses.
I do something like this for packages I maintain that require Java. I don't detect the Java version, but I do say 'This package requires Java' (the reason for this is that there are so many flavours and versions, it would be impossible to get it right all the time). . So I'd suggest the following:
# check PowerShell Core is available
if (Get-Command -Name 'pwsh.exe' -ErrorAction SilentlyContinue) {
# we've confirmed PowerShell Core is available, retrieve the version of it
$hostVersion = [Version]((pwsh.exe -Command { $PSVersionTable }).PSVersion)
# does the version of PowerShell Core installed meet the minimum version we need?
if ([Version]$hostVersion -lt [version]$minPSVersion) {
# better to use 'Write-Warning' here
throw "$moduleName module requires a minimum of PowerShell v$minPSVersion."
}
}
else {
# better to use 'Write-Warning' here
throw "$moduleName module requires a minimum of PowerShell v$minPSVersion."
}
(I've briefly tested this code, and it works, but check it). (note that I wrote this to make it readable rather than concise - you can combine both if
statements into one line)
What this does it check that PowerShell Core is installed. If not, it throws the exception. If it is installed, it runs the host and grabs the PSVersion
from $PSVersionTable
and then compares it to what you need.
A suggestion would be not to throw, but to use Write-Warning
. The package can be installed without PowerShell Core installed and you should therefore allow the install, to take place with a warning that the module can't be run without them installing PowerShell Core. You could even help by providing them the command to install PowerShell Core: choco install powershell-core
.
Or, the better way, is to simply add a dependency on a minimum version, 6.2.0, of powershell-core
as a package dependency. That way you don't need any of the above as it will be taken care of for you.
from choco.
Thanks for all the suggestions here! They're super helpful.
I'll give adding powershell-core as a dependency and Pauby's script a try.
from choco.
Chocolatey CLI only supports Windows PowerShell as an internal host. I'm unsure if --use-system-powershell
will use PowerShell Core if it's installed. @gep13 @AdmiringWorm may have the answer to that.
from choco.
Related Issues (20)
- Detecting elevated command shell works for PowerShell 7, but not for PowerShell 5 and CMD HOT 2
- Tab completion does not work since PowerShell 7.4 HOT 12
- Install of sass fails with unrelated dependency HOT 1
- Take (error) colors from the profile of the user
- Verify command line flags (by default) HOT 10
- During upgrade of a package not all files in the lib folder are present HOT 1
- Unexpected behevior from search --exact HOT 3
- Add command to allow viewing any rules implemented by Chocolatey CLI or an extension
- Provide docker containers based on Server Core LTSC 2019 and 2022 HOT 3
- Chocolatey fails to downgrade using local source when not using the `--version` option HOT 7
- Install-ChocolateyZipPackage might contribute to VirusTotal false positive HOT 2
- One app failed to update break all other app updates. HOT 1
- Choco Push results in 504 (Gateway Time-out) (home network)
- Searching for specific version on v3 only feed returns no results
- chromium package lost when I did CTRL C HOT 3
- Install-ChocolateyZipPackage needs -SpecificFolder64
- The choco always prompts for credentials HOT 7
- Choco deleted my `oh-my-posh` installation whilst uninstalling `neovim 0.9.5` HOT 4
- Update help output to reflect that the Proxy BypassList is a regular expression
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from choco.