Install-Module in PowerShell: Get Modules from PSGallery

Install-Module in PowerShell: Get Modules from PSGallery

PowerShell Tips Editor 4 min read
Install-Module in PowerShell: Get Modules from PSGallery

The PowerShell Gallery hosts over 10,000 modules — everything from Azure management to Excel generation to Active Directory automation. Knowing how to search, install, update, and manage these modules transforms what you can accomplish without writing a single line of utility code. This guide covers everything you need to use PowerShell Install-Module effectively, including scope, offline installation, and repository trust.

Quick Answer / TL;DR

# Install a module for yourself (no admin needed)
Install-Module -Name ImportExcel -Scope CurrentUser

Searching with Find-Module

Before installing, search the Gallery to find the right module and verify it’s maintained:

# Search by name keyword
Find-Module -Name '*dns*'

# Search by tag
Find-Module -Tag 'ActiveDirectory'

# See full details of a module
Find-Module -Name 'PSWriteHTML' | Select-Object Name, Version, Author, PublishedDate, Description

# Find all modules from a specific author
Find-Module -Repository PSGallery | Where-Object { $_.Author -eq 'Doug Finke' }
Version Name         Repository Description
------- ----         ---------- -----------
7.8.9   ImportExcel  PSGallery  PowerShell Import and Export to Excel...
1.0.3   SimplySql    PSGallery  Execute SQL queries from PowerShell...

Check the PublishedDate and download count on the Gallery website before depending on a third-party module in production. Prefer modules with recent updates and high download counts.

Installing a Module for All Users vs Current User

The -Scope parameter controls where the module is installed:

# CurrentUser scope — installs in your profile, no admin needed
# Path: C:\Users\Username\Documents\PowerShell\Modules (PS7+)
# Path: C:\Users\Username\Documents\WindowsPowerShell\Modules (PS5.1)
Install-Module -Name Pester -Scope CurrentUser

# AllUsers scope — installs in Program Files, requires admin
# Path: C:\Program Files\PowerShell\Modules (PS7+)
Install-Module -Name PSReadLine -Scope AllUsers

# Install a specific version
Install-Module -Name Az -RequiredVersion 9.5.0 -Scope CurrentUser

# Install alongside existing version (side-by-side)
Install-Module -Name Pester -RequiredVersion 5.3.1 -Scope CurrentUser -Force

For personal or developer machines, CurrentUser is sufficient and avoids UAC prompts. For servers or shared build agents where all accounts need the module, use AllUsers.

Updating Installed Modules

# Update a specific module to the latest version
Update-Module -Name Pester

# Update all installed modules
Update-Module

# Check what would be updated (see current vs latest version)
Get-Module -ListAvailable | ForEach-Object {
    $installed = $_
    $online = Find-Module -Name $installed.Name -ErrorAction SilentlyContinue
    if ($online -and $online.Version -gt $installed.Version) {
        [PSCustomObject]@{
            Name      = $installed.Name
            Installed = $installed.Version
            Available = $online.Version
        }
    }
}
Name        Installed Available
----        --------- ---------
Pester      5.3.1     5.4.1
ImportExcel 7.7.0     7.8.9

Uninstalling a Module

# Uninstall a module
Uninstall-Module -Name ImportExcel

# Uninstall a specific version
Uninstall-Module -Name Pester -RequiredVersion 5.3.1

# Uninstall all versions except the latest
Get-Module -ListAvailable -Name Pester |
    Sort-Object Version -Descending |
    Select-Object -Skip 1 |
    ForEach-Object { Uninstall-Module $_.Name -RequiredVersion $_.Version }

Installing Without Internet (Offline)

On air-gapped or restricted machines, save modules from a connected system first:

# On connected machine: save module files to a local folder
Save-Module -Name ImportExcel -Path 'C:\Temp\Modules'

# Copy C:\Temp\Modules to the target machine, then:
# On target machine: install from local folder
Install-Module -Name ImportExcel -Repository (Register-PSRepository -Name Local -SourceLocation '\\server\share\Modules' -InstallationPolicy Trusted; 'Local') -Scope CurrentUser

# Simpler: just copy the module folder directly
# Copy C:\Temp\Modules\ImportExcel to:
# $env:USERPROFILE\Documents\PowerShell\Modules\ImportExcel

The simplest offline approach is to copy the saved module folder directly to the target machine’s module path. PowerShell will find it automatically without any registration.

Trusting the PSGallery Repository

The first time you run Install-Module, PowerShell prompts you to trust the PSGallery repository. To suppress this permanently:

# Trust the gallery
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

# Verify
Get-PSRepository
Name      InstallationPolicy  SourceLocation
----      ------------------  --------------
PSGallery Trusted             https://www.powershellgallery.com/api/v2

Common Errors and Fixes

  • Untrusted repository prompt — use -Force or Set-PSRepository: Add -Force to suppress the prompt for a one-time install, or run Set-PSRepository -Name PSGallery -InstallationPolicy Trusted to trust it permanently. In automation scripts, always set the repository trust level explicitly rather than relying on interactive prompts.
  • NuGet provider missing on fresh Windows installs: If you see “NuGet provider is required to continue,” allow PowerShell to install it: answer Y to the prompt, or pre-install with Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force.

Related Cmdlets / See Also

Wrapping Up

Install-Module makes the PowerShell Gallery’s 10,000+ modules available in seconds. Use -Scope CurrentUser to avoid admin prompts, trust the Gallery once with Set-PSRepository, and use Save-Module for offline deployments. Always check module version and maintenance status before relying on community modules in production. Your next step: install ImportExcel and start generating Excel reports directly from PowerShell.

Send-Item -To