PowerShell Install-Module Local vs CurrentUser
Categories:
PowerShell Install-Module: Local vs. CurrentUser Scope Explained
Dive into the nuances of installing PowerShell modules, understanding the critical differences between 'LocalMachine' and 'CurrentUser' scopes, and how to choose the right one for your environment.
Installing PowerShell modules is a fundamental task for any administrator or developer working with PowerShell. However, a common point of confusion arises when deciding between the LocalMachine
and CurrentUser
installation scopes. This article will clarify what these scopes mean, their implications for module accessibility and permissions, and provide practical guidance on when to use each.
Understanding Module Installation Scopes
When you use the Install-Module
cmdlet, you have the option to specify a Scope
parameter. This parameter dictates where the module files are stored and, more importantly, who can access and use them. The two primary scopes are LocalMachine
and CurrentUser
.
Install-Module
varies depending on whether you're running PowerShell as an administrator. If you run as administrator, the default is LocalMachine
. If not, the default is CurrentUser
.LocalMachine Scope
The LocalMachine
scope installs the module for all users on the system. This means any user who logs into that machine will have access to the installed module. This scope typically requires administrative privileges to perform the installation because it writes to system-wide directories. Modules installed with LocalMachine
scope are usually found in a path like $env:ProgramFiles\PowerShell\Modules
or $env:PSHome\Modules
.
Install-Module -Name Pester -Scope LocalMachine
Example of installing the Pester module for all users on the system.
LocalMachine scope provides system-wide access to modules.
CurrentUser Scope
The CurrentUser
scope installs the module only for the user who is currently logged in and performing the installation. This scope does not require administrative privileges, as it writes the module files to the user's personal profile directory. Modules installed with CurrentUser
scope are typically found in a path like C:\Users\<YourUsername>\Documents\PowerShell\Modules
or C:\Users\<YourUsername>\AppData\Local\PowerShell\Modules
.
Install-Module -Name Az.Accounts -Scope CurrentUser
Example of installing the Az.Accounts module for the current user only.
CurrentUser scope restricts module access to the installing user.
Get-Module -ListAvailable | Select-Object Name, Path
.When to Choose Which Scope
The choice between LocalMachine
and CurrentUser
depends heavily on your specific use case, environment, and security considerations.
1. Step 1
Choose LocalMachine when:
2. Step 2
Multiple users on the same system need access to the module (e.g., shared development machines, server environments).
3. Step 3
The module is a core component of system automation or scripts that run under different user contexts (e.g., scheduled tasks, service accounts).
4. Step 4
You want centralized management of modules for all users.
5. Step 5
Choose CurrentUser when:
6. Step 6
You are developing or testing a module and don't want to affect other users or the global system state.
7. Step 7
You lack administrative privileges on the machine and need to install a module for your personal use.
8. Step 8
You prefer isolated module environments for different users, preventing conflicts or versioning issues.
LocalMachine
might override or conflict with a CurrentUser
version if not managed carefully. PowerShell's module resolution order typically prioritizes CurrentUser
modules over LocalMachine
modules with the same name if they are in the PSModulePath
.