0

after configuring my PowerShell and installing Starship.rs, I wanted to install oh-my-posh. The instruction on the website for this is Install-Module oh-my-posh -Scope CurrentUser. I tried this but I get this error every time:

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).

I tried these things:

  • Run PowerShell as an Admin by right clicking the application, selecting the option and accepting the prompt
  • Change the command to this Install-Module -Scope CurrentUser oh-my-posh

But this didn't work neither. How can I install oh-my-posh now?

Some Information:

  • I am running Windows 11 Beta on a Surface Pro 7
  • I am running PowerShell 7.1.5
Leo1807
  • 13
  • 4
  • What is the value of `$PROFILE`? I've seen issues where if the PowerShell profile is stored in a OneDrive folder it is unable to install or remove modules. – heavyd Oct 15 '21 at 22:37
  • My `$PROFILE` is actually in my OneDrive folder: `$HOME\OneDrive\Documents\PowerShell\Microsoft.PowerShell_profile.ps1` – Leo1807 Oct 15 '21 at 22:51
  • How can I fix this? – Leo1807 Oct 15 '21 at 22:52
  • @Leo1807 - You are 100% you have elevated the permissions of the PowerShell 7.1 prompt to that of an Administrator? Have you tried elevating a PowerShell 5.1 prompt? – Ramhound Oct 15 '21 at 23:17
  • I am 100000% sure that I have elevated rights. When I execute the command in PowerShell 5.1 I get this error: `PackageManagement\Install-Package : A part of the path "C:\Users\leona\OneDrive\Dokumente\WindowsPowerShell\Modules\oh-my-posh\5.8.0" could not be found. In C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 sign:21 + ... $null = PackageManagement\Install-Package @PSBoundParameters` and more – Leo1807 Oct 15 '21 at 23:25
  • Suspect your issue is similar to [this](https://superuser.com/questions/1183955/how-do-i-install-and-import-the-powershell-community-extensions-for-a-normal-use) question – Ramhound Oct 15 '21 at 23:30
  • Add “-Verbose -Debug” and post it to something like pastbin, additionally, verify Controlled Folder Access is turned off. [Make sure you use the .MSI version of the PowerShell installer](https://github.com/PowerShell/PowerShellGetv2/issues/586) – Ramhound Oct 15 '21 at 23:39
  • Turning off Controlled Folder Acces was the solution, as I now have all the files and binaries in the `$HOME\OneDrive\Documents\PowerShell\Modules\oh-my-posh\5.8.0` folder. Thanks you! – Leo1807 Oct 16 '21 at 00:02

1 Answers1

1

after configuring my PowerShell and installing Starship.rs, I wanted to install oh-my-posh. The instruction on the website for this is Install-Module oh-my-posh -Scope CurrentUser. I tried this but I get this error every time:

I suspect the issue is due to a combination of needing to tweak Controlled Folder Access by adding an exception for pwsh.exe and the fact your profile is linked to your OneDrive folder. If you don’t want to bother with tweaking Controlled Folder Access you can simply disable it.

It also appears that this solution can be solved by NOT using the Windows Store to install PowerShell. Be sure to use the current .MSI installer instead.

Source: Falsely throws exception as 'Administrator rights required' when running already as an admin - Install-Module #586

Ramhound
  • 41,734
  • 35
  • 103
  • 130