Accessing Free PowerShell Gallery (Part 1)

by May 18, 2018

PowerShell is an extensible framework, and there are tons of free and very useful command extensions available on the PowerShell Gallery (www.powershellgallery.com). We’ll be examining the vast power of this gallery in a couple of tip posts.

To download and install any extension from PowerShellGallery, you need the PowerShellGet module which provides you with the commands to browse, download, install, update, and also remove extensions.

The PowerShellGet module ships with PowerShell 5, and here is how you can check whether you have access to this module:

 PS> Get-Module PowerShellGet -ListAvailable Directory: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 1.0.0.1 PowerShellGet {Install-Module, Find-...

If you are running PowerShell 5, you might want to check whether you are using the latest version. The installed version was reported by the previous command. To check the latest version available in the Gallery, do this:

 PS> Find-Module PowerShellGet Version Name Repository Description ------- ---- ---------- ----------- 1.6.0 PowerShellGet PSGallery PowerShell...

To update any module that was originally installed from the PowerShell Gallery, you’d simply run Update-Module, however this fails for PowerShellGet:

 PS> Update-Module PowerShellGet Update-Module : Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated. 

That’s because this module ships with Windows 10. To update it, you have to re-install the module manually. If you have Administrator privileges, it is strongly suggested that you open an elevated PowerShell first and install (update) the package below as a prerequisite:

 PS> Install-PackageProvider Nuget –Force Name Version Source Summary ---- ------- ------ ------- nuget 2.8.5.208 https://onege... N...

If you do not update the underlying package provider first, you may not be able to update the PowerShellGet module. Once you updated the package provider, close all PowerShell windows, and open a fresh PowerShell console to ensure it uses the updated package provider.

Next, install the latest version of PowerShellGet:

 PS> Install-Module –Name PowerShellGet –Force

If you do not have Administrator privileges, install PowerShellGet just for your user by using the -Scope CurrentUser parameter.

You now should be using the latest version of PowerShellGet alongside with the existing version:

 PS> Get-Module PowerShellGet -ListAvailable Directory: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Script 1.6.0 PowerShellGet {Install-Module, Find-Module... Script 1.0.0.1 PowerShellGet {Install-Module, Find-Module...

You can now flawlessly update the module via Update-Module (using the same privileges you used when you installed it):

 PS> Update-Module PowerShellGet

These are the new commands you have at your fingertips now:

 PS> Get-Command -Module PowerShellGet CommandType Name Version Sou rce ----------- ---- ------- --- Function Find-Command 1.6.0 Pow Function Find-DscResource 1.6.0 Pow Function Find-Module 1.6.0 Pow Function Find-RoleCapability 1.6.0 Pow Function Find-Script 1.6.0 Pow Function Get-InstalledModule 1.6.0 Pow Function Get-InstalledScript 1.6.0 Pow Function Get-PSRepository 1.6.0 Pow Function Install-Module 1.6.0 Pow Function Install-Script 1.6.0 Pow Function New-ScriptFileInfo 1.6.0 Pow Function Publish-Module 1.6.0 Pow Function Publish-Script 1.6.0 Pow Function Register-PSRepository 1.6.0 Pow Function Save-Module 1.6.0 Pow Function Save-Script 1.6.0 Pow Function Set-PSRepository 1.6.0 Pow Function Test-ScriptFileInfo 1.6.0 Pow ...

Twitter This Tip! ReTweet this Tip!