How to Install a Module in PowerShell Quickly and Easily
Use the
Install-Module cmdlet in PowerShell to install modules from the PowerShell Gallery. For example, run Install-Module -Name ModuleName in an elevated PowerShell window to install a module.Syntax
The basic syntax to install a PowerShell module is:
Install-Module: The command to install modules.-Name: Specifies the module name to install.-Scope(optional): Defines if the module installs for the current user (CurrentUser) or all users (AllUsers).-Force(optional): Forces installation without prompts.
powershell
Install-Module -Name ModuleName [-Scope CurrentUser|AllUsers] [-Force]
Example
This example installs the popular PSReadLine module for the current user. It shows how to run the command and the expected output.
powershell
Install-Module -Name PSReadLine -Scope CurrentUser
Output
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet.
Do you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y
Installing module 'PSReadLine'...
Common Pitfalls
Common mistakes when installing modules include:
- Not running PowerShell as Administrator when installing for all users.
- Ignoring prompts about untrusted repositories.
- Trying to install a module without internet access.
- Using incorrect module names or typos.
Always verify the module name and run PowerShell with the right permissions.
powershell
## Wrong: Installing without admin for all users
Install-Module -Name PSReadLine -Scope AllUsers
## Right: Run PowerShell as admin before running
# Then run:
Install-Module -Name PSReadLine -Scope AllUsersQuick Reference
| Parameter | Description |
|---|---|
| -Name | Specifies the module name to install |
| -Scope | Defines installation scope: CurrentUser or AllUsers |
| -Force | Forces installation without confirmation prompts |
| -Repository | Specifies the repository to install from (default is PSGallery) |
| -AllowClobber | Allows overwriting existing commands |
Key Takeaways
Use Install-Module -Name ModuleName to install PowerShell modules.
Run PowerShell as Administrator when installing modules for all users.
Respond to prompts about untrusted repositories to proceed with installation.
Use -Scope CurrentUser to install modules without admin rights.
Verify module names and internet connection before installing.