- Run Docker container on Subsystem for Linux 2 (WSL 2) - Tue, Nov 24 2020
- Free up disk space on WSUS server by deleting expired and superseded updates - Thu, Nov 19 2020
- Monitor update status of Windows 10 PCs with Microsoft's free Update Compliance - Mon, Nov 16 2020
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.
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.
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.
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:
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
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.
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.