Since WMF 5.0, a package manager called “PackageManagement” has become available and let you install programs from the command-line. A package manager keeps track of softwares installed on your computer, and allows you to easily install new software or remove software that you previously installed.

What is PackageManagement?

PackageManagement (also known as “OneGet”) is a new way to discover and install software packages from around the web.

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

It is a manager or multiplexor of existing package managers (also called package providers) that unifies Windows package management with a single Windows PowerShell interface. With PackageManagement, you can do the following:

  • Manage a list of software repositories in which packages can be searched, acquired and installed
  • Discover software packages
  • Seamlessly install, uninstall, and inventory packages from one or more software repositories

Below is the architecture:

PackageManagement Architecture

Download Banner

Basically, a user can install a package from a provider which can be an officially-supported “Microsoft” provider or a 3rd party provider to expand the possibilities. Package Sources are also called “Repositories”. This is the place where the software packages are stored.
Now, let’s take a look at some examples of how to automate package installation with PowerShell.

PackageManagement Module

PackageManagement module requires PowerShell v5.

PackageManagement module requires PowerShell v5

Thanks to this PowerShell module, you can:

  • List installed software
  • Search a package
  • Install a package
  • Uninstall a package
  • Save a package without installing it

More information: https://technet.microsoft.com/en-us/library/dn890951.aspx

How to install “PackageManagement”?

First, you must check which version is available on PowerShell Gallery. So please navigate to:https://www.powershellgallery.com/packages/PackageManagement and check the latest version. Actually, the latest version is 1.1.4.0.

PackageManagement is integrated in Windows 10 and Windows Server 2016 but it’s the very first version. So you should update the version by running the following command:

install PackageManagement

If you don’t specify the parameter, Windows will warn you:

warning packagemanagement

Note: Don’t forget to close your PowerShell console and reopen it to refresh the module version.

Let’s imagine you want to install another version (it’s hope to you), then you just have to specify the version using the RequiredVersion parameter followed by the number:

PackageManagement-RequiredVersion

How to install a Package Provider?

Packages are stored in many repositories by different providers. You can list the available providers:

install a Package Provider

The previous command doesn’t indicate that all these providers are registered on your machine. It means that you can install them if you want! So now, if you want to add a new Package Provider, you just have to run the following:

Install-PackageProvider-chocolatey

Let’s confirm by running the Get-PackageSource cmdlet, and you will see the chocolatey provider which is now available.

I suggest that you mark repositories as “Trusted” in order not to confirm package installation each time. By default, the repositories are marked as “untrusted”, so the following command will trust them and you will have no warning message:

Set-PackageSource -Name chocolatey – Trusted

If you no longer want to use a repository, you can remove it very simply:

Unregister-PackageSource-name-Chocolatey

How to install a Package?

OK, everything is configured! You can install your first package. To perform this task, you must find the package. Let’s start by installing Notepad++:

Find-Package-Name-notepad-Source-Chocolatey

Note: Use wildcard if you don’t know the name.

Run the installation of Notepad++:

install-package-notepad

Great, Notepad++ has been installed!

Notepad++

I can confirm with the following:

get-package-notepad

Of course, you can install several applications using a single command:

install-several-applications using a single command

How to Uninstall a Package?

You can easily uninstall a package using the “Uninstall-Package” cmdlet:

uninstall-notepad

Conclusion

Thanks to PackageManagement, you can now quickly and easily deploy packages using Windows PowerShell. PackageManagement will help you in your day-to-day sysadmin tasks by managing and deploying your packages. This new feature required to have command-line skills because there is no GUI for the moment.

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Rate this post