-
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
User context, don't install to %OneDriveCommercial%
if OneDrive for Business Known Folder Move (KFM) is enabled
#627
Comments
%OneDriveCommercial%
if OneDrive for Business Known Folder Move (KFM) is enabled
Thanks @o-l-a-v for opening this issue, we are investigating this-- to confirm have you hit this issue with our v3 previews? |
Don't remember if I've tried with v3 yet. Should be easy enough for you to reproduce? :) |
Tested with beta 3.0.12, it installs to
# Import module downloaded from PowerShellGallery, extracted with 7-Zip
Import-Module -Name ('{0}\powershellget.3.0.12-beta\PowerShellGet.psd1' -f [System.Environment]::GetFolderPath('Desktop'))
# Check imported modules
Get-Module
# Install a module in user context
PowerShellGet\Install-PSResource -Name 'Az.Cdn' -Scope 'CurrentUser' -Repository 'PSGallery' -Quiet -Confirm:$false -TrustRepository -Reinstall |
Thanks @o-l-a-v we are planning to do a deeper dive into these (and other path) issues after our next release |
%OneDriveCommercial%
if OneDrive for Business Known Folder Move (KFM) is enabled%OneDriveCommercial%
if OneDrive for Business Known Folder Move (KFM) is enabled
Honestly, whether or not the changes in PowerShell/15552 are made, having a parameter set which gives us the ability to specify the On company developer laptops, OneDrive routinely causes "Access to the cloud file is denied" errors when trying to upgrade modules there, and starts needlessly mirroring the files back to the cloud, slowing down install even more. Not to mention that every time I remove an old version of Az or Microsoft.Graph it causes that scary warning about how something has deleted thousands of files from my OneDrive... |
I was more than happy to solve this in OneDrive "Choose Folders" option, but that doesn't work remotely the way I expected. I just wanted to exclude the Modules folder from syncing entirely but unchecking it in that screen does very different things than that. |
Having modules roam between machines (via OneDrive) is desired functionality for me! Please don't turn it off! I can see that some might want to turn it off, which they can at the moment by setting I can also see that some sort of alternative mechanism might be desired - eg. some sort of placeholder file, etc. although not all modules are available from the gallery, so quite a bit of design required there. I would strongly recommend caution when breaking existing workflows by disabling/altering the currently enabled-by-default feature. |
@fowl2 thanks for reaching out and providing insight into your use case with this default behavior. This is being discussed and worked on from the PowerShell project side, on this issue linked here: PowerShell/PowerShell#15552 If you can share this comment there, that would be great thanks. |
After some more tinkering I've found a solution that works for me. 1. Decide on desired directoryI settled on 2. Create desired directoryThe desired directory must be created prior to step 4. Example code$DesiredDirectory = [string] '{0}\Microsoft\PowerShell\Modules' -f $env:LOCALAPPDATA
if (-not [System.IO.Directory]::Exists($DesiredDirectory)) {
$null = [System.IO.Directory]::CreateDirectory($DesiredDirectory)
} 3. Set user context environmental variable
|
I have not researched the behavior of PowerShellGet v3, but in v2, when the |
Summary of the new feature / enhancement
Behavior today
Default install location for PowerShell scripts and modules when specifying user context, is:
%USERPROFILE%\Documents\WindowsPowerShell\Modules
%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:
%OneDriveCommercial%\Documents\WindowsPowerShell\Modules
%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:
It could also:
[System.Environment]::GetEnvironmentVariable('PSModulePath','<scope>')
.PackageManagement
,PowerShellGet
andMicrosoft.PowerShell.PSResourceGet
from old path given scope to new path.Option 2 - Use first path in
$env:PSModulePath
if setIf 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.
%USERPROFILE%\Documents\WindowsPowerShell\Modules
%USERPROFILE%\Documents\PowerShell\Modules
Option 4 - Change default location for user scope to
%LOCALAPPDATA%
Change default location for user context to:
%LOCALAPPDATA%\WindowsPowerShell\Modules
%LOCALAPPDATA%\PowerShell\Modules
The text was updated successfully, but these errors were encountered: