0
0
PowershellHow-ToBeginner · 3 min read

How to Use Install-Module in PowerShell: Simple Guide

Use the Install-Module cmdlet in PowerShell to download and install modules from the PowerShell Gallery. Simply run Install-Module -Name ModuleName to install a module by its name. You may need to run PowerShell as administrator and confirm prompts for first-time use.
📐

Syntax

The Install-Module cmdlet installs one or more modules from an online repository like the PowerShell Gallery.

Key parts:

  • -Name: Specifies the module name to install.
  • -Scope: Defines if the module installs for the current user (CurrentUser) or all users (AllUsers).
  • -Force: Forces installation without prompts.
  • -Repository: Specifies the source repository, default is PSGallery.
powershell
Install-Module -Name <ModuleName> [-Scope CurrentUser|AllUsers] [-Force] [-Repository <RepositoryName>]
💻

Example

This example installs the popular PSReadLine module for the current user. It shows how to run the command and the typical 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. PSReadLine Do you want to install the module from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y Installing module 'PSReadLine'... Module 'PSReadLine' was installed successfully.
⚠️

Common Pitfalls

Common mistakes when using Install-Module include:

  • Not running PowerShell as administrator when installing for all users.
  • Ignoring prompts about untrusted repositories.
  • Trying to install a module that is already installed without using -Force.
  • Not having the PowerShellGet module updated, which can cause errors.
powershell
## Wrong: Installing without admin for all users
Install-Module -Name PSReadLine -Scope AllUsers

## Right: Run PowerShell as admin or install for current user
Install-Module -Name PSReadLine -Scope CurrentUser
📊

Quick Reference

Tips for using Install-Module effectively:

  • Use -Scope CurrentUser to avoid needing admin rights.
  • Use -Force to reinstall or update modules silently.
  • Check installed modules with Get-InstalledModule.
  • Update PowerShellGet with Install-Module PowerShellGet -Force if you face issues.

Key Takeaways

Run Install-Module with the module name to install from PowerShell Gallery.
Use -Scope CurrentUser to install without admin rights.
Confirm prompts about untrusted repositories or set repository as trusted.
Use -Force to reinstall or update modules without prompts.
Keep PowerShellGet updated to avoid installation errors.