PowerShellGet Introduction

PowerShellGet Introduction

With PowerShell version 5 Microsoft released a way of installing modules using PowerShell. Before v5 you would have to copy modules into specific folders where the module folder name has to be exactly has the module .psd1 file. Getting it right for someone who wasn’t writing modules was hard. I know at work I would simply copy the files for them into C:WindowsSystem32WindowsPowerShellv1.0Modules so the modules could be loaded in the user’s session.

Those days are thankfully gone. PowerShellGet works off of the NuGet package management framework devised for Visual Studio and allows anyone to install Modules with ease. Shipping currently in the latest v5 version users can install modules with the following command:

[code lang=powershell]
Find-Module -Name Powershellcookbook | Install-Module -Verbose
[/code]

You’ll notice that by default PowerShell does not trust the repository in which you are downloading from. PowerShell ships with a module gallery populated with modules from the community. These are not modules vetted by Microsoft but some modules do come from Microsoft employees. The PowerShellCookbook module happens to be written by Lee Holmes, a Microsoft employee who works on Windows Server. Other modules are written by Microsoft MVPs and other respectable leaders in the community. There is a chance that the content you download could be malicious. Always inspect any module you download from any unverified source.

In order to checkout repository information run Get-PSRepository.

[code lang=powershell]
Get-PSRepository | format-list *
[/code]

Notice how the InstallationPolicy property is set to untrusted. You should keep it untrusted since you don’t know who is actually posting the module. In the future you may stand up your own NuGet repository where you vet all published content. Then, you can set your repository to trusted to bypass any confirmations.

Running Install-Module again and excepting the confirmation means that you now have the module installed. Running Get-InstalledModule reveals a list of Modules you’ve installed from Install-Module.

[code lang=powershell]
Get-Installed
Module Version Name Repository Description ——- —- ———- ———– 1.3.2 PowerShellCookbook PSGallery Sample scripts from the Windows PowerShell Cookbook
[/code]

To confirm we actually have PowerShellCookbook installed we run on of the cmdlets named Show-Object.

[code lang=powershell]
Get-Process -name Powershell | Show-Object
[/code]

Show-Object is useful for exploring new object types. You can drill into the objects and their properties in a visual way to see exactly what is in them.

When new versions of modules come out you simply have to run Update-Module to get the latest version.

[code lang=powershell]
Update-Module
[/code]

Be sure to check out the other commands inside of PowerShellGet.

[code lang=powershell]
get-command -Module powershellget
[/code]

2 thoughts on “PowerShellGet Introduction

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.