12

My $env:PSModulePath has ended up containing OneDrive:

C:\Users\jack\OneDrive\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

But I don't want all my Modules being synced to the cloud.

According to the docs:

The user-specific CurrentUser location on Windows is the PowerShell\Modules folder located in the Documents location in your user profile ... Microsoft OneDrive can also change the location of your Documents folder.

So that explains how the Modules ended up there. But how do I fix it?

I can modify $env:PSModulePath but this will only allow pwsh to find more modules I think. It won't change the default path for installing new modules for CurrentUser.

P.S. I face the same problem with the Update-Help when it saves help locally... OneDrive :-(

Jack Ukleja
  • 13,061
  • 11
  • 72
  • 113

1 Answers1

3

Perhaps the information in this thread on Reddit, could be of help.

Here's a snip from one of the answers, talking about excluding certain folders:

You can accomplish this by opening the OneDrive settings on your PC.

  1. Go to OneDrive settings
  2. Click the Account tab
  3. Click "Choose Folders" and then cherry pick the folders you want to exclude.
  • 1
    You can also navigate to the folder in question, right click, and select `always keep on this device`. – JohnLBevan Aug 04 '21 at 14:59
  • 1
    @JohnLBevan that would just create a local copy of the folder. The `always keep on this device` feature allows the user to modify files stored in the cloud without needing Internet access. Once they connect to the Internet again, the local copy is compared to the cloud version and reconciled. It's not a security feature to block a given folder from syncing to the cloud, nor would it keep the PowerShell modules within from being synced, which is what the OP indicates in both title and post they are trying to prevent. – killshot13 Nov 22 '21 at 03:44
  • @killshot13 true; my suggestion is based on the potential that this is an XY problem, where modules not being on the local device is the issue, rather than their being in the cloud. – JohnLBevan Nov 22 '21 at 07:26
  • 1
    @JohnLBevan fair enough, this could be an XY type of question. I originally came across this post because I actually am searching for a solution where Powershell is maintained on my Windows machine and nothing is being synced to the cloud. Since I am limited to 100GB unless I upgrade my subscription, I have to prioritize what I want to store on the cloud vs. external storage. – killshot13 Nov 22 '21 at 09:36