“Administrator rights are required to install modules” means Install-Module tried to write to Program Files without elevation. The quick fix is to install it for your account only:
Install-Module PSScriptAnalyzer -Scope CurrentUser
In this tutorial, I’ll reproduce the administrator rights are required to install modules error on a standard Windows account, then walk through four fixes in PowerShell 7 and Windows PowerShell 5.1.
Why does Install-Module say administrator rights are required?
The AllUsers scope writes to C:\Program Files, and only an elevated session can do that. My test account isn’t in the local Administrators group, so this fails:
Install-Module PSScriptAnalyzer -Scope AllUsers
Output (PowerShell 7):
Install-Module: C:\psfaqs\repro.ps1:1
Line |
1 | Install-Module PSScriptAnalyzer -Scope AllUsers
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Administrator rights are required to install modules in 'C:\Program Files\PowerShell\Modules'. Log on to the
| computer with an account that has Administrator rights, and then try again, or install
| 'C:\Users\alice\OneDrive\Documents\PowerShell\Modules' by adding "-Scope CurrentUser" to your command. You can
| also try running the Windows PowerShell session with elevated rights (Run as Administrator).

I replaced my user name with alice. In 5.1, the path in the message is C:\Program Files\WindowsPowerShell\Modules.
The bigger difference is the default scope. It depends on your PowerShellGet version, so check your PowerShell version and the Install-Module version:
(Get-Command Install-Module).Version.ToString()
Output (PowerShell 7):
2.2.5
Windows PowerShell 5.1 prints 1.0.0.1. PowerShellGet 1.x defaults to AllUsers, so 5.1 fails even when you leave out -Scope:
try { Install-Module PSScriptAnalyzer -Force -ErrorAction Stop }
catch { $_.FullyQualifiedErrorId }
Output:
InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module
Fix 1: Install the module with -Scope CurrentUser
CurrentUser installs into your own Documents folder, which needs no admin rights. -Force skips the “Untrusted repository” prompt for PSGallery:
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force
(Get-Module PSScriptAnalyzer -ListAvailable).ModuleBase
Output (PowerShell 7):
C:\Users\alice\OneDrive\Documents\PowerShell\Modules\PSScriptAnalyzer\1.25.0
