0
0
PowerShellscripting~5 mins

Installing modules (Install-Module) in PowerShell

Choose your learning style9 modes available
Introduction

Modules add new commands to PowerShell. Installing modules lets you use extra tools easily.

You want to add new commands to automate tasks.
You need to use a specific feature not built into PowerShell.
You want to share your scripts with others using common modules.
You want to update or install the latest version of a tool.
You are setting up a new computer and need required modules.
Syntax
PowerShell
Install-Module -Name <ModuleName> [-Scope <Scope>] [-Force] [-AllowClobber]

-Name is the module name you want to install.

-Scope can be CurrentUser (just you) or AllUsers (everyone on the PC).

Examples
Installs the PowerShellGet module for the current user by default.
PowerShell
Install-Module -Name PowerShellGet
Installs the Pester module only for the current user.
PowerShell
Install-Module -Name Pester -Scope CurrentUser
Installs or updates the Az module, forcing overwrite if needed.
PowerShell
Install-Module -Name Az -Force -AllowClobber
Sample Program

This script installs the PSReadLine module for the current user and confirms the installation.

PowerShell
Install-Module -Name PSReadLine -Scope CurrentUser -Force
Write-Output "Module PSReadLine installed successfully."
OutputSuccess
Important Notes

You may need to run PowerShell as Administrator to install modules for all users.

If you get a prompt about an untrusted repository, type 'Y' to continue.

Use Get-InstalledModule to see what modules are installed.

Summary

Install-Module adds new commands by downloading modules.

Use -Scope to control who can use the module.

Use -Force to overwrite existing modules if needed.