Skip to content

AWS.Tools.Installer v1.0.3 fails to Uninstall "Roamed" Modules if OneDrive Known Folder Move is Configured #399

@franklesniak

Description

@franklesniak

Describe the bug

On Windows, OneDrive Known Folder Move redirects the Documents folder to OneDrive. Windows PowerShell 5.1 places its per-user-installed modules in %DOCUMENTS%\WindowsPowerShell\Modules and PowerShell 7.x places its in %DOCUMENTS%\PowerShell\Modules - therefore, per-user-installed modules sync to OneDrive and "roam" from computer to computer.

If a module is installed on "ComputerA" and roams to "ComputerB", ComputerB will be able to use the module, but it won't be registered in PowerShell's installed module manifest. Therefore, if the user uses Install-AWSToolsModule with the -Cleanup flag to uninstall old versions, the process will fail with errors like the following:

PS C:\Users\flesniak> Install-AWSToolsModule AWS.Tools.Common, AWS.Tools.SecurityHub -CleanUp;

Confirm
Are you sure you want to perform this action?
Performing the operation "Uninstall-AWSToolsModule" on target "AWS Tools version 5.0.67".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
Uninstalling AWS.Tools version 5.0.67
Uninstalling module AWS.Tools.ConfigService
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.ConfigService'.
Uninstalling module AWS.Tools.IdentityManagement
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.IdentityManagement'.
Uninstalling module AWS.Tools.SecurityHub
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.SecurityHub'.
Uninstalling module AWS.Tools.SSO
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.SSO'.
Uninstalling module AWS.Tools.SSOOIDC
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.SSOOIDC'.
Uninstalling module AWS.Tools.Common
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.Common'.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

If Install-AWSToolsModule is going to clean up old versions of modules, I would like it to be able to remove modules that were synced over from OneDrive.

Current Behavior

PS C:\Users\flesniak> Install-AWSToolsModule AWS.Tools.Common, AWS.Tools.SecurityHub -CleanUp;

Confirm
Are you sure you want to perform this action?
Performing the operation "Uninstall-AWSToolsModule" on target "AWS Tools version 5.0.67".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
Uninstalling AWS.Tools version 5.0.67
Uninstalling module AWS.Tools.ConfigService
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.ConfigService'.
Uninstalling module AWS.Tools.IdentityManagement
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.IdentityManagement'.
Uninstalling module AWS.Tools.SecurityHub
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.SecurityHub'.
Uninstalling module AWS.Tools.SSO
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.SSO'.
Uninstalling module AWS.Tools.SSOOIDC
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.SSOOIDC'.
Uninstalling module AWS.Tools.Common
Uninstall-Package: No match was found for the specified search criteria and module names 'AWS.Tools.Common'.

Reproduction Steps

  • Have two Windows systems, each configured with OneDrive Known Folder Move on a shared OneDrive account
  • Install some modules on the first system, e.g., Install-AWSToolsModule AWS.Tools.Common, AWS.Tools.SecurityHub -CleanUp;
  • Wait a few days for module updates to publish
  • On the second system, run the command Install-AWSToolsModule AWS.Tools.Common, AWS.Tools.SecurityHub -CleanUp;

Possible Solution

To fix this, the call to PowerShellGet\Uninstall-Module @uninstallModuleParams could be wrapped in a try-catch block, with a catch block specifically for this exception. In that catch block, enumerate the modules present in the modules folder and their versions, then for each module, sort by version and queue anything older than the most recent version for deletion. Then, use Remove-Item to remove it.

I use the following script to do this, which also serves as my workaround in the meantime:

https://frenchcries-my.sharepoint.com/:u:/p/flesniak/Ef0uvrVVsvdCv7Y3hgl34DQBjaOBbgygytdOW_D4rKsfbw?e=lfSWrR

It's a bit tricky because the versions of modules in the PowerShell Gallery are not version objects - they are strings. So, a version like 1.3.beta1 is allowed. I had to write a function to gracefully convert these sorts of strings into a proper version object for sorting purposes.

Additional Information/Context

No response

AWS Tools for PowerShell version used

AWS.Tools.Installer v1.0.3

PowerShell version used

Name Value


PSVersion 7.5.3
PSEdition Core
GitCommitId 7.5.3
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Operating System and version

Windows 11 25H2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions