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 to

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 was used.

Eventually I discovered that the 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\\ Microsoft.Open.AzureAD16.Graph.PowerShell.dll

My speculation is that PowerShell installed the 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 "" -Scope AllUsers

After the installation, the module files are in:

Get-Module -Name AzureADPreview | fl                                                       

Name              : AzureADPreview
Path              : C:\Program Files\WindowsPowerShell\Modules\AzureADPreview\\ 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.

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

  1. Thanks. I was having the same problem after updating the old msonline module, and this got me going in the right direction. My guess is Windows or Powershell sees that the .dll is in OneDrive, and it considers OneDrive to be an “internet” site, so it won’t load the dll. There’s probably a way to “fix” that, but installing it for AllUsers does a better job, imho.

Leave a Reply

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