Installing a Module from the PowerShell Gallery
- By Adam Bertram
For the longest time, the open source community had a ubiquitous concept called "public package repositories." Using utilities such as rpm, yum et al. is commonplace, but Microsoft never had the same -- until the PowerShell Gallery.
The PowerShell Gallery was introduced to be a repository of packages from PowerShell modules and software packages where the community could share packages with one another. Using the built-in PowerShellGet module, anyone using PowerShell can upload, discover and download all kinds of packages.
Let's see how we can use the PowerShell Gallery to install a module.
First, we need to figure out what module we're looking for. Using the Find-Module command, we can search the gallery's repository of modules using wildcards. Perhaps I'm looking for a module around Active Directory. I can use Find-Module -Name *activedirectory* to discover all of the modules available.
PS> Find-Module *activedirectory*
Version Name Repository Description
------- ---- ---------- -----------
188.8.131.52 xActiveDirectory PSGallery The xActiveDirectory module is originally part of the Windows PowerShell D...
184.108.40.2063 Microsoft.Azure.ActiveDirectory.... PSGallery This module provides cmdlets to perform Azure AD Privileged Identity Manag...
220.127.116.11 ActiveDirectoryTools PSGallery Custom tools for automating Active Directory management and setup. I've pu...
1.6.0 CPolydorou.ActiveDirectory PSGallery Active Directory Helper Functions
18.104.22.168 ActiveDirectoryStig PSGallery Contains functions to set Active Directory STIG requirements that are not ...
1.1.1 cActiveDirectory PSGallery Module with DSC Resources for Active Directory
17.0.66... ActiveDirectoryCmdlets PSGallery CData Cmdlets for Active Directory
1.1.4 POSHOrigin_ActiveDirectoryDNS PSGallery POSHOrigin_ActiveDirectoryDNS is a set of PowerShell 5 based DSC resources...
1.0.0 ActiveDirectoryFever PSGallery PowerShell Module with additional custom functions and cmdlets for Windows...
22.214.171.124 myActiveDirectory PSGallery This module allows creation (deletion not currently covered) of Active Dir...
0.0.5.1 SUBnet192.ActiveDirectory PSGallery PowerShell module for Active Directory Custom Tasks
Once I've found the module I'm looking for, I can run Install-Module, which would both download and install the module, or I can simply pipe the modules found from Find-Module directly to Install-Module.
Perhaps I want to install the DSC module xActiveDirectory from the gallery. I need to limit the results that Find-Module returns by only specifying the name of the single module. This will only return the xActiveDirectory module.
Once I do that, I can then pipe that directly to Install-Module.
PS> Find-Module -Name xActiveDirectory | Install-Module
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the modules from 'https://www.powershellgallery.com/api/v2/'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): a
PS> Get-Module xActiveDirectory
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 126.96.36.199 xActiveDirectory
You can see above that when I run Install-Module, it asks me if I trust the source or not. This is the default behavior. You can override this by changing the installation policy as the message suggests, or by using the Force parameter.
This method can be used to install any module from the PowerShell Gallery or, if you already know the name of the module, you can call Install-Module directly and use the Name parameter using Install-Module -Name xActiveDirectory.
Adam Bertram is a 20-year veteran of IT. He's an automation engineer, blogger, consultant, freelance writer, Pluralsight course author and content marketing advisor to multiple technology companies. Adam also founded the popular TechSnips e-learning platform. He mainly focuses on DevOps, system management and automation technologies, as well as various cloud platforms mostly in the Microsoft space. He is a Microsoft Cloud and Datacenter Management MVP who absorbs knowledge from the IT field and explains it in an easy-to-understand fashion. Catch up on Adam's articles at adamtheautomator.com, connect on LinkedIn or follow him on Twitter at @adbertram or the TechSnips Twitter account @techsnips_io.