PowerShell / PowerShell/PSResourceGet

User context, don't install to `%OneDriveCommercial%` if OneDrive for Business Known Folder Move (KFM) is enabled

Open
#627 14 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Paths feature_request
Dominant language
C#
Stars
576
Forks
114
Avg merge
1d 2h
Merged PRs (30d)
7

Description

Summary of the new feature / enhancement

Behavior today

Default install location for PowerShell scripts and modules when specifying user context, is:

  • Windows PowerShell: %USERPROFILE%\Documents\WindowsPowerShell\Modules
  • PowerShell Core: %USERPROFILE%\Documents\PowerShell\Modules

But if you have OneDrive for Business set up with Known Folder Move (KFM), default install location for user context is:

  • Windows PowerShell: %OneDriveCommercial%\Documents\WindowsPowerShell\Modules
  • PowerShell Core: %OneDriveCommercial%\Documents\PowerShell\Modules
Why is it a problem

This is not ideal, as you'll end up with hundreds or thousands of small files that will be synced up and down to OneDrive, which might cause OneDrive sync issues, and other performance hits.

I currently install all modules to AllUsers scope for this reason. Currently 2.7 GB, 12 617 files, 2 315 folders.

Screenshot

image

If I did not care about this myself, I'd be using more than 1 / 10 of the capacity / max number of files recommendation for the OneDrive client, just for PowerShell modules.

Proposed technical implementation details

In my opinion, there is no reason to install PowerShell modules from PowerShell Gallery to OneDrive by default when KFM is active. A publicly available PowerShell module is nothing unique that needs to be backed up/ synced.

Option 1 - Cmdlet to set PSResourceLocation for Process/User/Machine

Add cmdlet to set PSResourceLocation for scope Process/User/Machine. For instance:

Set-PSResourceLocation -Scope 'Process' -Path ('{0}\Microsoft\PowerShell' -f $env:LOCALAPPDATA)

It could also:

  • Add path to [System.Environment]::GetEnvironmentVariable('PSModulePath','<scope>').
  • Have a Boolean parameter that specifiec whether to move modules and scripts installed by PackageManagement, PowerShellGet and Microsoft.PowerShell.PSResourceGet from old path given scope to new path.
    • Ask user if parameter wasn't specified.
Option 2 - Use first path in $env:PSModulePath if set

If I've set [System.Environment]::GetEnvironmentVariable('PSModulePath','User').Split(';')[0] to be somewhere else than the default location for <scope>, use it.

Option 3 - Don't follow KFM redirect

Users must opt in to install PowerShell modules to OneDrive, instead of current default behavior.

  • Windows PowerShell: %USERPROFILE%\Documents\WindowsPowerShell\Modules
  • PowerShell Core: %USERPROFILE%\Documents\PowerShell\Modules
Option 4 - Change default location for user scope to %LOCALAPPDATA%

Change default location for user context to:

  • Windows PowerShell: %LOCALAPPDATA%\WindowsPowerShell\Modules
  • PowerShell Core: %LOCALAPPDATA%\PowerShell\Modules

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation files, entry points, or tests. First clarify which of the four proposed approaches is intended, then locate the user-scope install-path resolution and its Windows PowerShell and PowerShell Core coverage. Done should mean the chosen behavior is implemented and verified for OneDrive Known Folder Move scenarios without breaking normal user-context installs.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.