PowerShell PowerTip: searching and installing modules on the command line

Kory Thacher

PowerShell 5+ ships with the module PowerShellGet, which lets us search and install modules from cmdlets. The default nuget repository is the PowerShell Gallery, but you could add others yourself (including custom ones for internal modules).

There are a lot of reasons this could help you:

  • You need a custom module installed on a machine for a remote script. This lets us build in the logic to detect if it is there, and install it if its not. Additionally we can use remoting to just install a module on a bunch of machines at once.
  • It will install your modules to the best-practice install location by default: C:\Program Files\WindowsPowerShell\Modules\
  • It feels more like the Linux terminal for interactive work

There are a lot of cmdlets in the module, but the ones you’ll use the most will be:

  1. Find-Module
  2. Install-Module (you’ll probably want to run this as an admin)

You can also specify the scope on install-module and put it in your user module location for ones just for you on a machine.

Hope that helps, tune in more often to get short and sweet PowerTips!

0 comments

Discussion is closed.

Feedback usabilla icon