PowerShell Install-Module: Use Install-Package Instead


When I restarted in the Windows ecosystem, I was installing PowerShell modules like this:

Install-Module 'PSDscResources'

This is similar to installing a Python package with pip in Linux:

pip install ansible

Install-Module installs PSDscResources from the PowerShell Gallery. Pip installs Ansible from PyPI.

Like the Linux ecosystem, the Windows ecosystem has several package databases. The PS Gallery I linked above. Chocolatey Packages. The NuGet Gallery. They each host different kinds of software, similar to how you can install different kinds of software from PyPI, Ruby Gems, and yum/apt.

In Linux, you work with each system separately from the others. In Windows, you can work with them separately, but you usually shouldn’t. Microsoft built PackageManagement (formerly OneGet) to orchestrate the different package repositories. Now, each source of packages is implemented in a “Provider”. There’s a provider for the PS Gallery (called PowerShellGet) and another for Chocolatey. PackageManagement gives you a single interface to all of them through one set of cmdlets. Check out their architecture diagram.

So, we don’t need to use Install-Module to work directly with PS Gallery. Instead, we can just ask PackageManagement to install what we need and it’ll figure out where to get it from:

Install-Package 'PSDscResources'

You can also do things like check where an installed package came from:

Get-Package 'PSDscResources'
Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
PSDscResources                https://www.powershellgallery.c… PowerShellGet

In Linux, work with each package manager separately. In Windows, just use PackageManagement.

Happy automating!


Need more than just this article? We’re available to consult.

You might also want to check out these related articles: