The Install-Module cmdlet in PowerShell is used to download and install modules from the PowerShell Gallery or other repositories. Modules in PowerShell are packages that include cmdlets, providers, functions, workflows, variables, and aliases that help automate tasks and manage systems.
Here's a detailed breakdown of how to use Install-Module:
```powershell Install-Module -Name <ModuleName> [-Force] [-Scope <CurrentUser]] | ] [-Repository <RepositoryName>] [-Credential <PSCredential>] [-AllowClobber] [-MinimumVersion <Version>] [-MaximumVersion <Version>] [-RequiredVersion <Version>] ``` ### Parameters - **-Name**: Specifies the name of the module to install. - **-Force**: Forces the installation of the module without user interaction. - **-Scope**: Specifies the installation scope: - `CurrentUser` (installs for the current user only). - `AllUsers` (requires administrative privileges and installs for all users). - **-Repository**: Specifies the repository from which to install the module. - **-Credential**: Provides the credentials to use for the installation. - **-AllowClobber**: Allows the cmdlet to overwrite existing commands that have the same names as commands in the module being installed. - **-MinimumVersion**: Specifies the minimum version of the module to install. - **-MaximumVersion**: Specifies the maximum version of the module to install. - **-RequiredVersion**: Specifies the exact version of the module to install. ### Examples #### Install a Module from the PowerShell Gallery ```powershell Install-Module -Name PSReadline ``` This command installs the latest version of the [[PSReadline module from the PowerShell Gallery.
```powershell Install-Module -Name AzureRM -Scope CurrentUser ``` This command installs the AzureRM module for the current user without requiring administrative privileges.
```powershell Install-Module -Name AzureRM -RequiredVersion 2.1.0 ``` This command installs version 2.1.0 of the AzureRM module.
```powershell Install-Module -Name MyModule -Repository MyCustomRepo ``` This command installs the module named MyModule from a custom repository named MyCustomRepo.
If the repository requires authentication, you can provide credentials: ```powershell $cred = Get-Credential Install-Module -Name MyModule -Repository MyPrivateRepo -Credential $cred ```
If you need to overwrite existing commands, use the `-AllowClobber` parameter: ```powershell Install-Module -Name MyModule -AllowClobber ```
To update installed modules, you can use the Update-Module cmdlet: ```powershell Update-Module -Name MyModule ```
The Install-Module cmdlet is a powerful tool for managing PowerShell modules, allowing administrators and users to easily extend the functionality of PowerShell by installing additional cmdlets and features.