powershell_module_installation

PowerShell Module Installation

Return to PowerShell, PowerShell Topics

Installing PowerShell modules is a common task for extending the capabilities of PowerShell. Modules can be installed from the PowerShell Gallery or other repositories. Here’s a comprehensive guide on how to install PowerShell modules.

  1. Steps to Install a PowerShell Module
  1. 1. Open PowerShell as an Administrator

To install modules system-wide, you need administrative privileges. Right-click on PowerShell and select “Run as administrator.”

  1. 2. Verify PowerShell Version

Ensure you have a compatible version of PowerShell by checking your PowerShell version: ```powershell $PSVersionTable.PSVersion ```

  1. 3. Register the PowerShell Gallery Repository

Ensure that the PowerShell Gallery is registered as a repository: ```powershell Get-PSRepository ``` If the PowerShell Gallery is not listed, register it: ```powershell Register-PSRepository -Default ```

  1. 4. Install the Module

Use the `Install-Module` cmdlet to install the module. For example, to install the `AzureAD` module: ```powershell Install-Module -Name AzureAD ```

If you encounter a prompt about an untrusted repository, confirm the installation by responding with `Y` (Yes) or `A` (Yes to All).

  1. 5. Import the Module

After installation, import the module into your current session: ```powershell Import-Module AzureAD ```

  1. 6. Verify Installation

Ensure that the module is installed and loaded by listing the available cmdlets: ```powershell Get-Command -Module AzureAD ```

  1. Handling Common Issues
  1. Untrusted Repository

If you see a warning about an untrusted repository, you can set the PowerShell Gallery as a trusted repository: ```powershell Set-PSRepository -Name PSGallery -InstallationPolicy Trusted ```

  1. Updating PowerShellGet and PackageManagement

If you encounter issues, ensure that you have the latest versions of `PowerShellGet` and `PackageManagement`: ```powershell Install-Module -Name PowerShellGet -Force -AllowClobber Install-Module -Name PackageManagement -Force -AllowClobber ```

  1. Running PowerShell as Administrator

Ensure you are running PowerShell with administrative privileges to install modules system-wide.

  1. Example: Installing the AzureAD Module

Here is the complete sequence of commands to install the `AzureAD` module:

```powershell

  1. Open PowerShell as an Administrator
  1. Check PowerShell version

$PSVersionTable.PSVersion

  1. Check the registered repositories

Get-PSRepository

  1. Register the PowerShell Gallery repository if not listed

Register-PSRepository -Default

  1. Install the AzureAD module

Install-Module -Name AzureAD

  1. Import the AzureAD module

Import-Module AzureAD

  1. Verify the installation

Get-Command -Module AzureAD ```

  1. Example: Installing Multiple Modules

You can install multiple modules in a single script. Here is an example:

```powershell

  1. Modules to install

$modules = @(“AzureAD”, “Az”, “PSReadline”)

foreach ($module in $modules) {

   Install-Module -Name $module -Force -AllowClobber
   Import-Module $module
}

  1. Verify installations

$modules ]] | [[ ForEach-Object { Get-Command -Module $_ } ```

  1. Installing from a Custom Repository

If you need to install a module from a custom repository, register the repository first:

```powershell

  1. Register a custom repository

Register-PSRepository -Name CustomRepo -SourceLocation “https://customrepo.example.com/nuget/v2” -InstallationPolicy Trusted

  1. Install a module from the custom repository

Install-Module -Name CustomModule -Repository CustomRepo ```

  1. Updating and Uninstalling Modules
  1. Updating a Module

To update a module to the latest version: ```powershell Update-Module -Name AzureAD ```

  1. Uninstalling a Module

To uninstall a module: ```powershell Uninstall-Module -Name AzureAD ```

By following these steps, you can effectively manage PowerShell modules, ensuring that you have the necessary tools and extensions for your automation and management tasks.

powershell_module_installation.txt · Last modified: 2025/02/01 06:35 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki