2

I am administrator on my Windows10, and trying to install Azure PS module as per the documentation in here.

PS C:\Program Files\PowerShell\7> Install-Module -Name Az -Scope CurrentUser -Force -Allowclobber

However, I get the error message as below..

Install-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:9711
Line 9711 talledPackages = PackageManagement\Install-Package @PSBoundParameters

Administrator rights are required to install or update. Log on to the computer with an account that has Administrator rights, and then try again, or install by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).

It does not make sense why it throws this error even though I am already in admin privilege mode. Few other SO answers asked to set to use TLS 1.2, I have done that as well. Like so:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

What else could be the issue ?

Dai
  • 141,631
  • 28
  • 261
  • 374
Anand Sowmithiran
  • 2,591
  • 2
  • 10
  • 22

1 Answers1

12

Trying to install az module over existing modules will give this error and it appears to be the cause for this issue.

The way to solve this issue is by deleting already existing not in use previous az modules which you can find in the following path -

C:\Program Files\WindowsPowerShell\Modules.

Then run the following command -

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force -AllowClobber

And this will solve your problem.

Also look at az module falsely throws Admin rights required error.

You can also check this discussion and find the similar answer in this comment.

Alireza Maddah
  • 5,718
  • 2
  • 21
  • 25
SauravDas-MT
  • 1,224
  • 1
  • 4
  • 10
  • Thanks, deleting all the Az modules from other location present in PSModulePath and then installing with ```Install-Module``` worked. In addition, I also excluded my OneDrive path from the PSModulePath by updating the powershell.config.json file. – Anand Sowmithiran Sep 17 '21 at 16:59
  • I also found that these files were also present in this path C:\Program Files (x86)\WindowsPowerShell\Modules Do we need to delete from there as well? – Sid May 27 '22 at 10:20
  • I also ended up installing Az module in this path C:\Users\username\OneDrive\Documents\PowerShell\Modules Will that be an issue? – Sid May 27 '22 at 10:26
  • In stead of deleting the module from this folder and blindly allowing clobber, you can delete it by using the Visual Studio Installer or Apps & Features. This is the recommended way, otherwise it might be installed by Visual Studio again. https://learn.microsoft.com/en-us/powershell/azure/troubleshooting?view=azps-9.4.0#visual-studio – Tiamo Idzenga Feb 16 '23 at 14:15
  • I had the same error and I upgraded my PS. I'm not sure the previous version, but I think I was a PS 7.1.x version. When I upgraded to 7.3.2 I was able to install using this answer's command. I had rebooted, tried uninstalling Az and several Az.* modules, uninstalled Visual Studio Enterprise 2019 and its installer, etc. prior to upgrading PS. – successhawk Feb 23 '23 at 04:39