The developers have included a new PowerShell module PackageManagement in Windows 10. PackageManagement (earlier called OneGet) allows to install, manage and uninstall applications and programs from an external (or local) repository, and manage the list of connected repositories from the PoSh console. In other words, now you can install programs from the command prompt in Windows 10/ Windows Server 2016 like they do it in Linux using the well-known command apt-get install.
The PackageManagement module makes it easy to install new software. The installation comes down to running a single PowerShell command, and a user doesn’t have to search and download software distributions in the Web, thus reducing the risk of downloading an outdated or infected programs. Software is installed from a trusted source. When software is updated in a repository, it can be automatically updated on the clients.
PackageManagement module is already integrated in Windows 10, and it requires PowerShell 5. To make PackageManagement work under Windows 8.1, you will have to install Windows Management Framework 5.0 first. Microsoft has also issued a separate PackageManagement module to work in PowerShell v.3 and 4.
Display the list of available PowerShell cmdlets in PackageManagement module:
Get-Command -Module PackageManagement
In the current version of the module (v 220.127.116.11) the following commands are available:
- Find-Package – search a package (program) in the available repositories
- Get-Package – show a list of installed packages
- Get-PackageProvider – display the list of package providers available on the computer
- Get-PackageSource – list available package sources
- Install-Package – install a package (program) on the computer
- Register-PackageSource – add a package source for the provider
- Save-Package – save a package locally without installing it
- Set-PackageSource – set a provider as a package source
- Uninstall-Package – uninstall a program (package)
- Unregister-PackageSource – remove a provider from the list of package sources
Packages are serviced by different providers that can receive packages from different sources. To display the list of available providers, run this command:
By default, there are two installed package sources in the system: nuget.org and PSGallery (official online gallery of PowerShell scripts from MSFT). First of all, they are designed for programmers and system administrators.
To access the application software repository, let’s connect a popular software repository – Chocolatey containing over 4,500 different programs.
Install a new provider, Chocolatey:
Confirm the provider installation by pressing Y.
Make Chocolatey a trusted package source in order not to confirm package installation each time.
Set-PackageSource -Name chocolatey -Trusted
Make sure that Chocolatey is now available among the application repositories:
Name ProviderName IsTrusted Location
---- ------------ --------- --------
PSGallery PowerShellGet False https://www.powershellgallery.com/api/v2/
chocolatey Chocolatey True http://chocolatey.org/api/v2/
Installing applications from the Chocolatey repository
Let’s see how to install an application (a package) from Chocolatey.
A list of available applications can be obtained directly from the official Chocolatey website (https://chocolatey.org/packages)
You can also find and install an apps right from the PowerShell console. For example, to view PDF files we have to install Adobe Acrobat Reader. Since we don’t know the full name of the application, we needed to get the name of the package in the directory to install it. Search the repository by the keyword “adobe”:
Find-Package -Name *adobe* -Source Chocolatey
The list of all packages containing this keyword will appear in the console. We need adobereader (it is the package name from the Name column that we need to use).
Run the installation of Adobe Reader package:
Install-Package -Name adobereader -ProviderName Chocolatey
On the top of PowerShell window, a slider will appear that indicates that Adobe Reader package is being downloaded. Immediately after the download is completed, the application is installed on the system.
Another example. Suppose, you need a set of tools SysInternals. In order not to download it manually, find SysInternals package in Chocolatey and install it.
Find-Package -Name Sysinternals | Install-Package
Since the package doesn’t need any installation, it is saved to your computer and stored in C:\Chocolatey\lib\. In our example, it is C:\Chocolatey\lib\sysinternals.2016.11.18\tools
You can install several applications at a time using a single command:
Find-Package -Name firefox, winrar, notepadplusplus, putty, dropbox | Install-Package
How to Uninstall a Package
You can also uninstall a package using just a single command. For example, to uninstall Adobe Reader run this command:
So, we have considered a new ways to install Windows applications from the PowerShell command prompt. In the nearest future, graphical add-ins for PackageManagement may appear that allow to easily manage installation/uninstallation of software for common users without CLI skills.