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)
- Pin using reason leads to wrong error message HOT 4
- choco hook package - post-install trigger does not fire when package installation fails HOT 7
- Get-ChocolateyWebFile.ps1 detected as malicious from ESET HOT 21
- Using `Install-ChocolateyPath -PathType Machine` in a non-admin context spawns PowerShell endlessly and never completes
- Deprecate `unpackself` command
- Rework build process to remove the use of `-unpackself`
- Remove `-unpackself` command and adjust build/debugging as appropriate
- Chrome package not installing HOT 1
- Change namespace casing to PascalCase HOT 2
- Improve package dependency lookup when an exact version is defined
- choco uninstalled a number of wrong packages when I want to uninstall ONE package HOT 6
- Autoremove feature or list leaf packages
- Chocolatey CLI v2.2.2 prompts for credentials when trying to install the ROS noetic desktop_full package HOT 2
- How to install choco without admin to local path user ? HOT 2
- dotnet4.5.2 was not found with the source(s) listed HOT 5
- Install-ChocolateyFileAssociation creating unnecessary 3rd parameter in registry command, causing error in app when opening associated filetype HOT 4
- Update GenerateDocs.ps1 to support the Astro Framework
- Install-ChocolateyPath: should -Scope default to 'Machine'
- Accessing icon from protected bin repo HOT 1
- Dependency resolution during install can be slow HOT 13
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.