Package Manager is a new feature in PowerShell 5.0 that allows you to download and install software packages from various sources. It also includes a provider for Microsoft installer and update files (MSI and MSU) to help manage Win32 programs.

Wolfgang Sommergut

Wolfgang Sommergut has over 20 years of experience in IT journalism. He has also worked as a system administrator and as a tech consultant. Today he runs the German publication WindowsPro.de.

On the one hand, Microsoft wants to provide a counterpart to Linux package managers such as RPM or apt-get that can download and install packages together with their dependencies from online resources.

Modular architecture ^

On the other hand, this new PowerShell feature is supposed to enable you to manage conventional MSI packages or updates in the MSU format. Thus, in theory, Package Manager can also serve as an alternative to the Control Panel's software management GUI.

Because Package Manager has to be able to process different kinds of formats, Microsoft adopted a modular approach where, depending on source and type, different providers come into play. Each provider can be responsible for one or multiple package sources. It already includes those providers for PowerShellGet, MSI, and MSU.

Displaying package providers with Get PackageProvider

Displaying package providers with Get PackageProvider

Cmdlets for all package management tasks ^

You can perform the following tasks with Package Manager:

  • Managing package sources and the corresponding providers
  • Searching software packages
  • Installing programs
  • Viewing and removing installed software

For these purposes, Package Manager gathers several cmdlets in the PackageManagement module. To get an overview of the available cmdlets, you can execute this command:

Viewing sources and installing providers ^

To get started, you probably will want to know which sources are available. Get-PackageSource is the cmdlet you need here.

Displaying sources with Get PackageSource

Displaying sources with Get PackageSource

You will learn which provider to use for a certain source and whether this source is trustworthy or not.

If you then want to display the available programs of an online repository like Chocolatey, you have to run the following command:

By default, PowerShell does not install the corresponding provider. However, it asks if you want to download and install the provider automatically when you first call it. To avoid this message, you can use the ForceBootstrap switch.

Automatically installing a Package Manager provider

Automatically installing a Package Manager provider

Searching and installing software ^

Because most of the package sources offer a large number of packages, you'll want to limit your search in most cases. You can use the parameter -Name for this purpose.

This example would find the MSI package for Notepad++. If you want to install the package, you can pass the result of this call through a pipe to Install-Package.

If you used a public repository, PowerShell will ask you if you trust the source and if you want to install software from it.

The execution policy hurdle ^

Package Manager then appears to download and install the program. However, sometimes you will then quickly realize that the procedure failed without giving any error message.

The reason is often the execution policy. To ensure that all scripts will run without any prompting, you can configure the Bypass policy:

Alternatively, you can manually download the MSI installer with a web browser and then execute the setup program via PowerShell:

The parameter -Force suppresses the question if you really want to install the package.

Package Manager treats all package formats equally. Thus, adding a PowerShell module through the PowerShellGet provider works in just the same way. The only difference is that you would then use PSGallery as source.

Displaying installed programs ^

After you install a Win32 application, it usually appears in the Control Panel under Programs and Features > Uninstall a program. You can display the same list of programs with this PowerShell command:

Displaying installed programs with PowerShell and in the Control Panel

Displaying installed programs with PowerShell and in the Control Panel

Like before, the -Name parameter allows you to restrict the output:

In theory, you could pass the result of this command to Uninstall-Package to remove the software:

However, in my tests the cmdlet always failed to uninstall the program.

In addition to applications, you can list the installed updates through the MSU provider:

The output of this command is more informative than that of Get-Hotfix because the property Summary gives you a description of the patches.

Conclusion ^

PowerShell's Package Manager (v5.0) is a comprehensive framework for adding and removing various software packages. You can also install it on older Windows versions through the WMF.

However, because of Package Manager's universal approach, you have to fiddle with different providers and package sources. This sometimes makes it a bit cumbersome to use. You also have to consider that the default repositories Microsoft provides are community projects and are therefore not trustworthy.

Finally, managing Win32 programs with Package Manager is unreliable and often requires working with an execution policy of the lowest security level.

Win the monthly 4sysops member prize for IT pros

Share
2+

Users who have LIKED this post:

  • avatar

Related Posts

1 Comment
  1. Rob 4 months ago

    Consider that as of May 2017, the PackageManagement Chocolatey Provider is still a non-fully functional prototype that was written by Microsoft a couple of years ago. We recommend choco.exe or the ChocolateyGet provider instead. There are more details about that at chocolatey-oneget/#5.

    Keep in mind you can maintain your own packages and host them internally, all with the freely available edition of Chocolatey. Then you don't have to battle with trust or reliability, as you would have everything internal and offline. HTH

    0

Leave a reply

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

*

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2017

Log in with your credentials

or    

Forgot your details?

Create Account