PowerShell Package Management System

Important

If you are using a pre 2016 server, install the following patch

https://www.microsoft.com/en-us/download/details.aspx?id=51451

Here is the file in case the link above is no longer available


If you have ever used Linux you will be used to the idea of applications like yum, apt-get, or rpm.  For a long time Windows had nothing like this, so third parties filled this gap e.g. NuGet, and Chocolatey.

Since 2003 Windows did have a package management system but it wasn't very good.  Since version 5x (2016), it has become more comprehensive and a lot easier to work with.  The new architecture looks like this

  • EndUser: As a user or sysadmin, you are in the “EndUser” section: This gives you access to several PowerShell cmdlets that we will use in the next section of this article.
  • PackageManagementCore: This corresponds to the actions that can be performed on your machine. Available actions are: discovery, install / uninstall and inventory.
  • PackageManagementProviders: This section regroups the providers that can interconnect to PackageManagementCore. It can be an officially-supported “Microsoft” provider or a 3rd party provider to expand the possibilities.
  • Package Sources: Also called “Repositories”. This is the place where the software packages are stored. These sources are managed by the providers themselves. Their location can be an online URL, a local folder or a network shared folder.

Basically an end user can install packages (libraries and executable software) from various sources.

Listing available Package Management CommandLets

Using a PowerShell window run the following command

shell command
get-command -module packagemanagement | sort noun, verb

It will yield the following result

Listing Available Package Providers

shell command
find-packageprovider

Listing Installed Package Providers

shell command
get-packageprovider

Adding a Package Provider

shell command
// install the package provider
install-packageprovider <provider-name> -verbose

// add the package provider to the list of available providers on your machine
import-packageprovider <provider-name>

// check if package provider installed correctly
get-packageprovider -verbose


Sample Code
// install the package provider
install-packageprovider ChocolateyGet  -verbose

// add the package provider to the list of available providers on your machine
import-packageprovider ChocolateyGet

// you might have to install something from the package provider to allow its commands to be executed, for example chocolatey requires the choco.exe file to be available as a Windows application, use the command below to install chocolatey as a separate Windows application
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

// check if package provider installed correctly
get-packageprovider -verbose

Installing a Package

shell command
// check if a package provider is available on your local machine
get-packageprovider -verbose

install-package <package-name>
// OR
install-package -source <provider-name> -name <package-name>
Sample Code
// see what package providers are available on your machine
get-packageprovider -verbose

install-package mysql

// you might get a warning ssaying there are multiple source providers, rerun the command as follows
install-package -source chocolatey -name mysql 

Complete example of installing a Package Provider and a Package

Sample Code
// Check if the package provider exists
find-packageprovider ChocolateyGet  -verbose

// install the package provider
install-packageprovider ChocolateyGet  -verbose

// add the package provider to the list of available providers on your machine
import-packageprovider ChocolateyGet

// now install a package
get-packageprovider -verbose
// if the above might fail because choco.exe needs to be aavailable, use the command below to install chocolatey as a separate Windows application
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

install-package mysql

// you might get a warning ssaying there are multiple source providers, rerun the command as follows
install-package -source chocolatey -name mysql