You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Two questions on the PSModulePath in PowerShell Core:
Is the the default setting of PSModulePath in PS Core documented anywhere (e.g. online) in a way that is general and cross platform? Like a table of what it is on each supported platform, or a string with unexpanded platform-specific variables in it? (e.g. $PSHOME/Modules:$AnotherPlace/SecondModuleDir)
Is it possible to access the default PSModulePath at runtime? (Or to reset the current one?)
It would also be nice to have it as an API endpoint perhaps (like a variable, static property, etc) -- like [ModuleIntrinsics]::GetModulePath() except without requiring arguments. Curious if anyone else has felt a need for that?
Reacted by Freddie Sackur and Mr Beedell, Roke Julian Lockhart
What I feel is absent is not necessarily the built-in default value, but a way to access the various well-known module locations by scope.
By analogy, let's take the example of $PROFILE, which contains the well-known profile locations as named-for-the-scope NoteProperty members:
# Sample output when run on macOS
PS>$PROFILE|Get-Member-type noteproperty | Select Name, Definition
Name Definition
--------------
AllUsersAllHosts string AllUsersAllHosts=/usr/local/microsoft/powershell/6-preview/profile.ps1
AllUsersCurrentHost string AllUsersCurrentHost=/usr/local/microsoft/powershell/6-preview/Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts string CurrentUserAllHosts=/Users/jdoe/.config/powershell/profile.ps1
CurrentUserCurrentHost string CurrentUserCurrentHost=/Users/jdoe/.config/powershell/Microsoft.PowerShell_profile.ps1
I think we should provide something similar for module locations, using scopes such as AllUsers, CurrentUser, System, and Custom (the latter comprising all $env:PSModulePath entries in addition to the well-known locations).
I'm unclear on how best to surface this functionality, however.
In theory, we could use the same approach as with $PROFILE: decorate the $env:PSModulePath[string] value with NoteProperty members, but that is somewhat obscure.
Then again, if properly documented, perhaps that's the way to go.
Reacted by Patrick Meinecke, Rob Holt, Mr Beedell, Roke Julian Lockhart and Thomas Nieto
I have submitted MicrosoftDocs/PowerShell-Docs#3214 to add the *nix locations to the existing about_Modules and about_Environment_Variables docs. I grant that this is only a partial solution.
Want to add that this may be of use in hosted PowerShell contexts where the hosting implementation might have reasons for using different paths for each module scope. (I would say "or possibly define its own", but I think we're coupled to the existing scopes now.)
It might merit being able to set the scoped module paths in the powershell.config.json and exposing their location through some PowerShell API. (Like Michael Klement (@mklement0), I'm not sure what shape that API should be -- but I'd opt for either a variable or a method call, with the latter being a more direct fit to the current implementation).
Rob Holt (@rjmholt) thanks very much for this, I'm using it in a module and, if I can get it working nicely, I'll publish it as a standalone script.
I note that on 5.1 and 6.0.1 on WIndows, and 6.1 on Linux, there is no GetWindowsPowerShellPSHomeModulePath method; it is only available on 6.1 on WIndows, AFAICS.
Oh good point. Yes, I wrote that method for 6.1. Windows PowerShell should have some method like that in it, but I don’t know what it is. The method I wrote is equivalent to just ”${env:windir}\System32\WindowsPowerShell\v1.0\Modules”
Thanks for the handy function, Rob Holt (@rjmholt) (also interesting to see the use of reflection to call the non-public methods - I hope we won't need that in the long run).
It seems that in Windows PowerShell only the method that returns the CurrentUser scope exists, so I've amended your function to add fallback values for Windows PowerShell.
(I've also changed the name to Get-StandardModulePath, shortened WindowsPSSystem to WinPSSystem and I'm using an ordered hashtable for the result, which makes the function v3+; btw, you forgot to rename a couple of instances of WindowsSystem to WindowsPSSystem in your recent edit).
Michael Klement (@mklement0) Yeah I opened this issue because I think those methods (or something like them) should really be a public API, since they are a contract with PSGet
Steve Lee (@SteveL-MSFT) is there a reason #11057 is marked as closing this issue? I couldn't find any new mechanism to solve feature request in that PR
Activity
SteveL-MSFT commentedon Jun 15, 2018
This is probably a
Documentation-Neededsituation. Currently, you'll probably have to look at the coderjmholt commentedon Jun 15, 2018
It would also be nice to have it as an API endpoint perhaps (like a variable, static property, etc) -- like
[ModuleIntrinsics]::GetModulePath()except without requiring arguments. Curious if anyone else has felt a need for that?SteveL-MSFT commentedon Jun 15, 2018
I think PSModulePath being an env var means you should get and set it like an env var
mklement0 commentedon Jun 17, 2018
What I feel is absent is not necessarily the built-in default value, but a way to access the various well-known module locations by scope.
By analogy, let's take the example of
$PROFILE, which contains the well-known profile locations as named-for-the-scopeNotePropertymembers:I think we should provide something similar for module locations, using scopes such as
AllUsers,CurrentUser,System, andCustom(the latter comprising all$env:PSModulePathentries in addition to the well-known locations).I'm unclear on how best to surface this functionality, however.
In theory, we could use the same approach as with
$PROFILE: decorate the$env:PSModulePath[string]value withNotePropertymembers, but that is somewhat obscure.Then again, if properly documented, perhaps that's the way to go.
SteveL-MSFT commentedon Jun 18, 2018
Bruce Payette (@BrucePay) you should take Michael Klement (@mklement0)'s suggestion as part of your
PSModulePath6RFCfsackur commentedon Oct 31, 2018
I have submitted MicrosoftDocs/PowerShell-Docs#3214 to add the *nix locations to the existing about_Modules and about_Environment_Variables docs. I grant that this is only a partial solution.
rjmholt commentedon Nov 7, 2018
Want to add that this may be of use in hosted PowerShell contexts where the hosting implementation might have reasons for using different paths for each module scope. (I would say "or possibly define its own", but I think we're coupled to the existing scopes now.)
It might merit being able to set the scoped module paths in the
powershell.config.jsonand exposing their location through some PowerShell API. (Like Michael Klement (@mklement0), I'm not sure what shape that API should be -- but I'd opt for either a variable or a method call, with the latter being a more direct fit to the current implementation).rjmholt commentedon Nov 7, 2018
In case anyone wants this btw, here's a quick function to get the defaults:
fsackur commentedon Nov 13, 2018
Rob Holt (@rjmholt) thanks very much for this, I'm using it in a module and, if I can get it working nicely, I'll publish it as a standalone script.
I note that on 5.1 and 6.0.1 on WIndows, and 6.1 on Linux, there is no
GetWindowsPowerShellPSHomeModulePathmethod; it is only available on 6.1 on WIndows, AFAICS.rjmholt commentedon Nov 13, 2018
Oh good point. Yes, I wrote that method for 6.1. Windows PowerShell should have some method like that in it, but I don’t know what it is. The method I wrote is equivalent to just
”${env:windir}\System32\WindowsPowerShell\v1.0\Modules”mklement0 commentedon Nov 13, 2018
Thanks for the handy function, Rob Holt (@rjmholt) (also interesting to see the use of reflection to call the non-public methods - I hope we won't need that in the long run).
It seems that in Windows PowerShell only the method that returns the
CurrentUserscope exists, so I've amended your function to add fallback values for Windows PowerShell.(I've also changed the name to
Get-StandardModulePath, shortenedWindowsPSSystemtoWinPSSystemand I'm using an ordered hashtable for the result, which makes the function v3+; btw, you forgot to rename a couple of instances ofWindowsSystemtoWindowsPSSystemin your recent edit).rjmholt commentedon Nov 14, 2018
Michael Klement (@mklement0) Yeah I opened this issue because I think those methods (or something like them) should really be a public API, since they are a contract with PSGet
mklement0 commentedon Nov 14, 2018
Ah, of course, Rob Holt (@rjmholt); so another thank you for opening this issue.
rjmholt commentedon Nov 28, 2019
Steve Lee (@SteveL-MSFT) is there a reason #11057 is marked as closing this issue? I couldn't find any new mechanism to solve feature request in that PR
JustinGrote commentedon Sep 4, 2024
Since this was erroneously closed, #15552 is probably the best location to continue discussion.