opsira

PowerShell modules break when Documents is synced to the cloud

In short

The module installed without error, appeared in the module list, and threw a malformed-module error every time it was used.

Installing a PowerShell module for the current user places it under your Documents folder. On a machine where Documents has been redirected into a cloud sync client, which is now the default on many setups, that is a folder being continuously synchronised in the background.

The result is a module that installs cleanly, lists correctly, and refuses to load, with an error saying it could not be correctly formed. Files may be placeholders rather than real content, or locked mid-sync. Either way the load fails, usually with an error that says nothing about the cause.

How to spot it

Get-Module <name> -ListAvailable | Select Name, Version, ModuleBase

If the module base path contains a sync client folder name, that is your problem.

The fix

Install-Module <name> -Scope AllUsers -Force -AllowClobber

Run it from an elevated session. That installs to the machine-wide location, which no sync client touches.

If uninstall refuses

An in-use module cannot be removed while any session has it loaded, and the sync client may hold a lock too. You do not need to remove the broken copy. Install alongside it and import by explicit path, or close every session and retry.

Two things that make it worse

Different shells use different paths. Modern PowerShell and Windows PowerShell keep separate module directories, so a module installed in one is invisible to the other. Combined with the sync problem this produces a convincing illusion that installation did nothing.

Some modules only load in one of them. A module built on the older runtime will not load in the newer shell and vice versa. If a command is unrecognised, check which shell you are in before reinstalling anything.

The general lesson: a successful install is not a successful load. Verify by importing, not by the absence of an error.

Need help with any of this?

These notes are free and always will be. If you would rather someone just set it up, or you are stuck on something similar, get in touch at hello@opsira.io.