-
Notifications
You must be signed in to change notification settings - Fork 95
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
Allow to specify custom module path in Install-PSResource #1494
Comments
cc @SydneyhSmith since this seems to be a PSResourceGet issue. |
@SydneyhSmith would it be possible to proritize this? I'm from Azure Data and we have very significant support costs in our org related to modules being in OneDrive. I can also reach out internally if needed. |
There is also the As long as the path is in PSModulePath |
@o-l-a-v Yes, this is also what I mentioned in the issue. But nobody will remember this all the time. You usually go to PowerShell Gallery and copy&paste the I would really prefer an environment variable or a one-time setting Set-PSDefaultResourceLocation, .. |
Oops, yep, also mentioned in 1st post. This is how PowerShell have worked since forever. We've requested the ability to choose path for years. I don't see it happening any time soon. Thus Save-PSResource and set PSModulePath is currently the best workaround IMO. I'd like PSResourcePath to just use the first path in PSModulePath in user context if choosing CurrentUser as scope (and PSModulePath env variable in system context if scope "Machine"). |
This module Why not changing a bit the behavoir or adding one parameter? |
This is blocking PowerShell/PowerShell/issues/15552 from moving forward. For far longer than PowerShell has been around, the Please, make the change so that this can move on. |
In windows, there is more than windows to think about with a change like this |
How about a new environment variable for given scope (AllUsers vs. CurrentUser), say Easy to implement. Should not introduce breaking changes. Don't have to wait for PowerShell to change anything. More reasoning: Click to viewConsiderationsChanging default behavior is breaking
Current default behavior is worse for Windows than Unix
Can't reliably use
|
I think it should just look at powershell.config.json (if it exists) and use the PSModulePath there (if it exists), and otherwise fall back to what it is now. If there is a powershell.config.json in If there is a powershell.config.json in in Those values will be in the PSModulePath, unless the user removes them, after startup. |
Setting PSModulePath in powershell.config.json says it "Overrides the PSModulePath settings for this PowerShell session.". Sounds to me you either set PSModulePath env variable, or as a setting in this JSON? That's not a great solution either. If it overrides PSModulePath the environment variable, then you'd potentially want multiple paths here too. Which path should PSResourceGet default to, the first one? |
You're misunderstanding it, @o-l-a-v -- I mean, I'm not saying the docs are great, but just try it. Each config file (one in Set your PSModulePath environment variables to short strings we can identify: [System.Environment]::SetEnvironmentVariable("PSModulePath", "PATH3", "User")
[System.Environment]::SetEnvironmentVariable("PSModulePath", "PATH4", "Machine") Start a new PowerShell instance (e.g. a new tab in Windows Terminal), the PSModulePath will be something like this:
Now set the user config file. It's important that you understand you can only put a single path to a folder in this string, to replace the native path (which would be a "Modules" folder adjacent to the config file). You can use other environment variables with %ComSpec% syntax, but you cannot put multiple folders with a path separator. For demonstration purposes, we'll again use a short string we can identify: $path = Join-Path (Split-Path $Profile) powershell.config.json
$config = @{}
if (Test-Path $path) {
$config = Get-Content $path | ConvertFrom-Json -AsHashtable
}
$config.PSModulePath = "PATH1"
$config | ConvertTo-Json | set-content $path And start a new PowerShell instance (e.g. a new tab in Windows Terminal), the PSModulePath will be something like this:
Finally, just to finish the demo, set the PSHome config:
And start a final PowerShell instance (you may want to run it
Hopefully it's clear how those configs interact with the environment variables, and why reading them makes sense (with a fallback to the default of a "Modules" folder next to the config file path, if they're not set). Incidentally, I find it really weird that the only path that cannot be overridden points at a folder that doesn't even exist on my systems. |
Oh, okay. Thats nice. And should work the same on all platforms. I should've tried rather than trusting the docs. Thanks for the very detailed explaination @Jaykul. 😊 Edit: But it can't be used with Windows PowerShell 5.1, which PSResourceGet also supports. |
@Jaykul - Yes thank you, I've banged my head against that before: it looks like it works at first, namely that the first entry in $PSModulePath is changed, but installing a module still installs to the old, default path, but now import-module can't find it. IMO this makes it worse-than-useless (because it breaks existing functionality for no trade-off). If you can get the rest of the ecosystem to honor |
@OranguTech wrote:
That's definitely my goal 😉 There's an issue in the ModuleFast repo too. They are not following this setting yet, but they do (by default) install the modules in |
For reference I've made a function that will be incorporated into moduleFast that provides how I envision PowerShell should be providing the info, hopefully a similar PR will reveal a public API for this. In summary and testing:
|
Summary of the new feature / enhancement
Install-Module and now also Install-PSResourceGet do not allow to specify the Path where Modules are installed. It only works via Save-Module or Save-PSResource.
It would be great if there is a environment variable or parameter to control where powershell modules are installed when using Scope CurrentUser
Proposed technical implementation details (optional)
No response
The text was updated successfully, but these errors were encountered: