PowerShell / PowerShell/PSResourceGet
User context, don't install to `%OneDriveCommercial%` if OneDrive for Business Known Folder Move (KFM) is enabled
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 576
- Fork
- 114
- Merge medio
- 1g 2h
- PR unite (30g)
- 7
Descrizione
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

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,PowerShellGetandMicrosoft.PowerShell.PSResourceGetfrom 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue non indica alcun file di implementazione, punto di ingresso o test. Per prima cosa chiarisci quale dei quattro approcci proposti è previsto, quindi individua la risoluzione del percorso di installazione nell'ambito utente e la relativa copertura per Windows PowerShell e PowerShell Core. Il lavoro dovrebbe considerarsi completato quando il comportamento scelto è implementato e verificato per gli scenari OneDrive Known Folder Move, senza compromettere le normali installazioni nel contesto utente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp, powershell
- Ambito
- cli, tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100