August 21st, 2018

PowerShell PowerTip: searching and installing modules on the command line

Kory Thacher
Premier Field Engineer

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!

Author

Kory Thacher
Premier Field Engineer

I've been a PFE since 2012, working with various technologies. I live in the modern applications domain, doing work in UWP apps, .NET, Unity, DevOps, and of course PowerShell. I've been teaching PowerShell related workshops very frequently for years, and I really enjoy getting the opportunity to explain a topic or learn something new from my colleagues. I enjoy scripting because of how fast and interactive it can be, and I love getting interesting problems to work on with customers. ...

More about author

0 comments

Discussion are closed.