PowerShell/PowerShellGetv2

PackageManagement\Install-Package fails with "Administrator rights are required to install or update." when run as administrator y bug report

yooakim opened this issue · 12 comments

Steps to reproduce

# Check if I am running in elevated command prompt:
[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
True

Install-Module AzureAd -Scope CurrentUser -Force

Expected behavior

Expect the module to be updated in the current user scope

The same issue has been reported in issue #12777 but that issue was closed as some users reported the problem had to do with Controlled Folder Access.

In my case controlled folder access is off but I still have the issue.

Actual behavior

Get this error. The error message is not correct as I am running from an elevated command prompt. So either the message is wrong or there is a bug.

Install-Module AzureAd -Scope CurrentUser -Force
Install-Package: C:\Users\yooak\OneDrive\Documents\PowerShell\Modules\PowerShellGet\2.2.5\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).

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

or install by adding "-Scope CurrentUser"

What will be if you try to install module without administrative elevation? I did never install modules with elevated PowerShell as "CurrentUser".

Same error if I try as a normal user, no difference @237dmitry

I have been experiencing a similar issue since Powershell 7.1.3 and I have checked with 7.2.0 preview 4 and the issue still exists.

Install-Package: 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).

image

I'm having a similar issue. I see your powerline fonts are also not working.

I keep seeing this error and I do not have Windows Defender Controlled Folder Access enabled. Any suggestions on how to get around this?

I have tried running without admin privileges and use - Scope CurrentUser, but it keeps telling me I need Admin privileges
image

Pease share output with Verbose switch.

I figured out how to reproduce this: use OneDrive's Auto Save (now called "Important PC Folders backup") to synchronize Documents folder, so that PowerShell modules and scripts are synchronized too. If modules were installed on other PCs, synchronized to this PC, then try to update or install them, this problem will occur. The workaround is to remove all modules and then reinstall them.

Remove all modules from OneDrive by deleting the files, then reinstall them will workaround this problem on the current machine.

#648 (comment)

Sorry for taking so long to reply @iSazonov - Here's the output from a new session (using PowerShell 7.1.4):

PS C:\Users\joakim.westin> Install-Module –Name PowerShellGet –Force -Verbose > .\Downloads\ps.log
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PowerShellGet'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'PowerShellGet'.
VERBOSE: Performing the operation "Install-Module" on target "Version '2.2.5' of module 'PowerShellGet'".
VERBOSE: The installation scope is specified to be 'CurrentUser'.
VERBOSE: The specified module will be installed in 'C:\Users\joakim.westin\OneDrive - X5 Music\Dokument\PowerShell\Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'PowerShellGet' with version '2.2.5' from the repository 'https://www.powershellgallery.com/api/v2'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PowerShellGet'' for ''.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='PackageManagement'' for ''.
VERBOSE: InstallPackage' - name='PackageManagement', version='1.4.7',destination='C:\Users\joakim.westin\AppData\Local\Temp\1327786590'
VERBOSE: DownloadPackage' - name='PackageManagement', version='1.4.7',destination='C:\Users\joakim.westin\AppData\Local\Temp\1327786590\PackageManagement.1.4.7\PackageManagement.1.4.7.nupkg', uri='https://www.powershellgallery.com/api/v2/package/PackageManagement/1.4.7'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PackageManagement/1.4.7'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PackageManagement/1.4.7'.
VERBOSE: Completed downloading 'PackageManagement'.
VERBOSE: InstallPackageLocal' - name='PackageManagement', version='1.4.7',destination='C:\Users\joakim.westin\AppData\Local\Temp\1327786590'
VERBOSE: InstallPackage' - name='PowerShellGet', version='2.2.5',destination='C:\Users\joakim.westin\AppData\Local\Temp\1327786590'
VERBOSE: DownloadPackage' - name='PowerShellGet', version='2.2.5',destination='C:\Users\joakim.westin\AppData\Local\Temp\1327786590\PowerShellGet.2.2.5\PowerShellGet.2.2.5.nupkg', uri='https://www.powershellgallery.com/api/v2/package/PowerShellGet/2.2.5'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/PowerShellGet/2.2.5'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/PowerShellGet/2.2.5'.
VERBOSE: Completed downloading 'PowerShellGet'.
VERBOSE: InstallPackageLocal' - name='PowerShellGet', version='2.2.5',destination='C:\Users\joakim.westin\AppData\Local\Temp\1327786590'
VERBOSE: Validating the 'PackageManagement' module contents under 'C:\Users\joakim.westin\AppData\Local\Temp\1327786590\PackageManagement.1.4.7' path.
VERBOSE: Test-ModuleManifest successfully validated the module manifest file 'C:\Users\joakim.westin\AppData\Local\Temp\1327786590\PackageManagement.1.4.7'.
VERBOSE: Validating the authenticode signature and publisher of the catalog file or module manifest file of the module 'PackageManagement'.
VERBOSE: Catalog file 'PackageManagement.cat' is not found in the contents of the module 'PackageManagement' being installed.
VERBOSE: Valid authenticode signature found in the file 'PackageManagement.psd1' for the module 'PackageManagement'.
VERBOSE: For publisher validation, current module 'PackageManagement' with version '1.4.7' with publisher name 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' from root certificate authority 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.
VERBOSE: For publisher validation, using the previously-installed module 'PackageManagement' with version '1.4.7' under 'C:\program files\powershell\7\Modules\PackageManagement' with publisher name 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' from root certificate authority 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.
VERBOSE: Authenticode issuer 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the new module 'PackageManagement' with version '1.4.7' matches with the authenticode issuer 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the previously-installed module 'PackageManagement' with version '1.4.7'.
VERBOSE: Checking for possible command collisions for the module 'PackageManagement' commands.
VERBOSE: Installing the dependency module 'PackageManagement' with version '1.4.7' for the module 'PowerShellGet'.
WARNING: The version '1.4.7' of module 'PackageManagement' is currently in use. Retry the operation after closing the applications.
VERBOSE: Module 'PackageManagement' is in currently in use or you don't have the required permissions.
VERBOSE: Validating the 'PowerShellGet' module contents under 'C:\Users\joakim.westin\AppData\Local\Temp\1327786590\PowerShellGet.2.2.5' path.
VERBOSE: Test-ModuleManifest successfully validated the module manifest file 'C:\Users\joakim.westin\AppData\Local\Temp\1327786590\PowerShellGet.2.2.5'.
VERBOSE: Validating the authenticode signature and publisher of the catalog file or module manifest file of the module 'PowerShellGet'.
VERBOSE: Catalog file 'PowerShellGet.cat' is not found in the contents of the module 'PowerShellGet' being installed.
VERBOSE: Valid authenticode signature found in the file 'PowerShellGet.psd1' for the module 'PowerShellGet'.
VERBOSE: For publisher validation, current module 'PowerShellGet' with version '2.2.5' with publisher name 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' from root certificate authority 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.
VERBOSE: For publisher validation, using the previously-installed module 'PowerShellGet' with version '2.2.5' under 'C:\Users\joakim.westin\OneDrive - X5 Music\Dokument\PowerShell\Modules\PowerShellGet\2.2.5' with publisher name 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' from root certificate authority 'CN=Microsoft Root Certificate Authority 2011, O=Microsoft Corporation, L=Redmond, S=Washington, C=US'. Is this module signed by Microsoft: 'True'.
VERBOSE: Authenticode issuer 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the new module 'PowerShellGet' with version '2.2.5' matches with the authenticode issuer 'CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US' of the previously-installed module 'PowerShellGet' with version '2.2.5'.
VERBOSE: Checking for possible command collisions for the module 'PowerShellGet' commands.
Install-Package: C:\Users\joakim.westin\OneDrive - X5 Music\Dokument\PowerShell\Modules\PowerShellGet\2.2.5\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).

I can add that my system has the following package management modules:

PS C:\Windows\System32> Get-Module -ListAvailable PackageManagement, PowerShellGet

    Directory: C:\Users\joakim.westin\OneDrive - X5 Music\Dokument\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.4.7                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     1.0.0.1               PackageManagement                   Desk      {Find-Package, Get-Package, Get-Package…
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Modu…

After spending much too much time on this I simply deleted all modules from my OneDrive/Documents/PowerShell/Modules folder and re-booted. After that it works.

So the underlying issue seems to be with the combination of OneDrive and PowerShell modules.

We have just released this version of PowerShellGet, 3.0.11-beta, can you please try this version out and if you are encountering the same problem you can open up a new issue here so we can investigate and resolve it.

Thanks @StevenBucher98 - I'll try that. Let's close this then.