Table of Contents
‘Access to the cloud file is denied‘ while installing a PowerShell module?
The error ‘Access to the cloud file is denied‘ makes you think it’s the PowerShell Gallery, but it’s probably your OneDrive and the location of your $env:PSModulepath
and then probably including the -Scope CurrentUser
parameter and variable.
There are several things you can try.
See the headers for different solutions.
FIX 1: With administrator permissions
What helped me were the following steps:
- Open PowerShell as Administrator
- Run the following cmdlet (change to the correct module name)
Install-Module -Name Az
Since you don’t use the -Scope CurrentUser
, PowerShell automatically grabs a different path in your $env:PSModulePath
.
If you want to read more about this, it’s best to go to this section ‘Windows PowerShell startup‘.
FIX 2: With disabling Files On-Demand in OneDrive
Not everyone has administrator rights on their device, but because the above step already worked for me, it’s difficult to troubleshoot further, but what I’m guessing the problem is is the OneDrive files On-Demand function.
You can disable this by opening the Settings of OneDrive and going to the Settings tab. Under Files On-Demand you can disable the option.
![FIX: Install-Package: Access to the cloud file is denied PowerShell](https://baswijdenes.com/wp-content/uploads/2022/04/image-249x300.png)
Windows PowerShell startup
Windows PowerShell uses the following logic to construct the PSModulePath
at startup:
- If
PSModulePath
doesn’t exist, combine CurrentUser, AllUsers, and the$PSHOME
modules paths - If
PSModulePath
does exist:- If
PSModulePath
contains$PSHOME
modules path:- AllUsers modules path is inserted before
$PSHOME
modules path
- AllUsers modules path is inserted before
- else:
- Just use
PSModulePath
as defined since the user deliberately removed the$PSHOME
location
- Just use
- If
The CurrentUser module path is prefixed only if User scope $env:PSModulePath
doesn’t exist. Otherwise, the User scope $env:PSModulePath
is used as defined.
Source: about PSModulePath – PowerShell | Microsoft Docs
So the structure of my $env:PSMODULEPATH
is as follows:
$env:PSMODULEPATH
C:\Users\BasWijdenes\OneDrive\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
This is an Array containing the CurrentUser, AllUsers, $PSHOME
modules locations from left to right.
My $PSHOME
looks like this (So, for the PowerShell module path it would add \Modules
):
$PSHOME
C:\Windows\System32\WindowsPowerShell\v1.0
Hello,
Just wanted to check with you if you’ve ever seen success for fix 2 yet? I have tried it and with Files On-Demand turned off, or even with OneDrive client “quit”‘ed altogether, this issue still occurs. For me it is with installing Microsoft.Graph.Sites. Simply cannot install it into CurrentUser with that = OneDrive, and without admin. rights. Ironically, several other Microsoft.Graph.*** modules will install just fine. Would love a non-admin + working solution for this problem.
Thanks nonetheless.