OneDrive Known Folders and PowerShell Module Installations

The OneDrive Known Folder Move feature has been around for a couple of years. Basically, this allows you to redirect common (well-known) folders from your PC to OneDrive so that anything created in Documents, Pictures, and the desktop is automatically saved in your OneDrive for Business account. Generally, everything works well, and I have been very happy.

Except until the time came to update the Azure Active Directory preview module from 2.0.2.77 to 2.0.2.89.

Problems Updating PowerShell Module

I followed my normal routine of upgrading the module from the PowerShell Gallery, but things didn’t work. And no combination of removing and reinstalling modules worked either, despite setting a required version for the Install-Module cmdlet. Each time I started PowerShell and connected to Azure Active Directory, version 2.0.2.78 was used.

Eventually I discovered that the 2.0.2.77 files were installed in OneDrive by examining the module properties:

Get-Module -Name AzureADPreview | fl

Name              : AzureADPreview
Path              : C:\Redmond\OneDrive – Office365ITPros\Documents\WindowsPowerShell\Modules\AzureADPreview\2.0.2.77\ Microsoft.Open.AzureAD16.Graph.PowerShell.dll

My speculation is that PowerShell installed the 2.0.2.77 files in OneDrive the last time I updated the module.

Clean up OneDrive and Reinstall

To clean up the mess, I uninstalled the module and then deleted all the files from OneDrive. A retention label stopped OneDrive deleting the files, so it was a matter of removing the retention label and then deleting the files and folders.

I then reinstalled the module, making sure to select the correct version and to install the module for everyone who uses the PC.

Install-Module AzureADPreview -RequiredVersion "2.0.2.89" -Scope AllUsers

After the installation, the module files are in:

Get-Module -Name AzureADPreview | fl                                                       

Name              : AzureADPreview
Path              : C:\Program Files\WindowsPowerShell\Modules\AzureADPreview\2.0.2.89\ Microsoft.Open.AzureAD16.Graph.PowerShell.dll

The next time I started a PowerShell session and ran the Connect-AzureAD cmdlet, I got the right version.

All of which goes to prove that you should pay attention to how you install PowerShell modules, just in case the files end up in OneDrive. PowerShell works when modules are installed to OneDrive, but upgrades become a little more interesting.

2 Replies to “OneDrive Known Folders and PowerShell Module Installations”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.