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.
Avatar

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:

Get-Command -Module PackageManagement

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:

Find-Package -Provider chocolatey

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.

Find-Package -Provider chocolatey -name notepad*

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.

Find-Package -Provider chocolatey -name notepadplusplus | 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:

Set-ExecutionPolicy Bypass

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

Install-Package -Name ".\7z920.msi" -force

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:

Get-Package -Provider Programs -IncludeWindowsInstaller
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:

Get-Package -Provider Programs -IncludeWindowsInstaller -Name "7-Zip*"

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

Get-Package -Provider Programs -IncludeWindowsInstaller -Name "7-Zip*" | Uninstall-Package

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:

Get-Package -Provider MSU | fl -Property name, summary

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.

Subscribe to 4sysops newsletter!

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

avataravataravatar
6 Comments
  1. Avatar
    Rob 7 years 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

    avatar
  2. Avatar
    Paul 5 years ago

    Has this situation changed? Using Find-PackageProvider does not list choco.exe or ChocolateyGet as providers.

    avatar
  3. Avatar
    SL 3 years ago

    I got mostly warnings.

    Microsoft, sigh …

  4. Avatar
    Sanoop Sadanandan 3 years ago

    Mozilla shows up in get-package  and is listed under provider name programs. Is there any alternative script to uninstall it using powershell as uninstall-package practically does nothing.  

  5. Avatar
    janus 3 years ago

    So how do we remove installed software? uninstall-package does not work for Programs ProviderName

Leave a reply

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

*

© 4sysops 2006 - 2023

CONTACT US

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

Sending

Log in with your credentials

or    

Forgot your details?

Create Account