PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Request to change default installation path for user modules

Open mgreenegit opened this issue 2 years ago • 6 comments

Summary of the new feature / enhancement

In the latest versions of OneDrive, the Documents folder is synchronized by default. This creates challenges for PowerShell users. Some might not want modules to "roam" between machines. In other cases, an organizational "My" folder always contains two spaces in the name following the pattern "OneDrive - OrgName". The spaces require using an 8.3 folder name or putting the path in quotations, which is extra work.

A community-suggested workaround is to move the default module path. The discussion resolved the best location to be ~/AppData/Local/PowerShell/Modules. The PowerShell committee has discussed and agrees with the approach and acknowledges that multiple steps in a coordinated effort will be required to reach the end goal without breaking compatibility.

https://github.com/PowerShell/PowerShell/issues/15552

Proposed technical implementation details (optional)

Two options for consideration, regarding Install-PSResource:

1 - Add a new parameter -InstallPath and set the default to $Env:HOMEPATH\AppData\Local\PowerShell\Modules. 2 - Just change the path where modules are installed to $Env:HOMEPATH\AppData\Local\PowerShell\Modules, without adding a parameter.

Additional options and considerations are welcome. If this is accepted, PWSH could add the path to PSModulePath (in addition to the existing) in a near-term release.

mgreenegit avatar Jul 20 '22 18:07 mgreenegit

Related/Duplicate: https://github.com/PowerShell/PowerShellGet/issues/627

ThomasNieto avatar Jul 20 '22 20:07 ThomasNieto

Related Linux should follow DBG conventions and save it in ~/.config/powershell/Modules

JustinGrote avatar Jul 21 '22 16:07 JustinGrote

100% support this. The target path (for windows) makes perfect sense as well.

Regarding migration:

  • Leave already installed modules where they are.
  • Leave the old path (for existing users) in the PSModulePath (but it could be removed for new profiles)
  • Add a cmdlet to migrate existing modules (Move-PSResource?). This could also allow migrating a currentuser module to machine (or back).
  • Consider Get/Set-PSResourcePath to set currentuser, default currentuser and machine paths?

markdomansky avatar Jul 21 '22 17:07 markdomansky

I second ~/AppData/Local/PowerShell/Modules location. Thats the first place I thought. It should be added in addition to the existing paths.

I would like to have a trivial way to inquire where the AllUser and CurrentUser scope install folders are. I see lots of repeated hard coded logic in scripts trying to figure this out on the fly. (checking OS and PS version, ect)

I don't think -InstallPath parameter is needed, but I would name it -Path (possibly with an alias of -InstallPath) to align with Save-PSResource.

KevinMarquette avatar Jul 21 '22 17:07 KevinMarquette

Install Path locations are pseudo-hard coded into PSGetV2 and PSGetV3. Either those modules should expose an API for the install locations or (even better), PowerShell engine should have an API that produces the recommended paths that is customizable preferably by a Cmdlet you put in your profile but a config.json or config.psd1 file somewhere would also work

JustinGrote avatar Jul 21 '22 17:07 JustinGrote

Here is where it is defined in PSGetv3 https://github.com/PowerShell/PowerShellGet/blob/2b4dab36195453edbd85789c9fdb8353b7c6130e/src/code/Utils.cs#L680-L707

And PSGetV2 https://github.com/PowerShell/PowerShellGetv2/blob/5aba7531f526b6e60b2757c36799995597b6dcec/Tests/PSGetTestUtils.psm1

JustinGrote avatar Jul 21 '22 17:07 JustinGrote