In this tutorial we will see about PowerShell PackageManagement and how we are able to use it.
What is PackageManagement
PackageManagement is also known as OneGet. PackageManagement has been introduced in Windows PowerShell 5.0. PackageManagement comes with Windows 10 and Windows Server 2016. It is a unified interface to package management systems and aims to make Software Discovery, Installation and Inventory (SDII) work via a common set of cmdlets (and eventually a set of APIs). Regardless of the installation technology underneath, users can use these common cmdlets to install/uninstall packages, add/remove/query package repositories, and query a system for the software installed.
PackageManagement works with:
- Package providers
- Package sources
Below is the architecture of PackageManagement exactly as provided in project site:
- Package manager – Software package management system. In PackageManagement terms, this is a package provider.
- Package provider – PackageManagement term for a package manager. Examples can include Windows Installer, Chocolatey, and others.
- Package source – A URL, local folder, or network shared folder that you configure package providers to use as a repository.
- Package – A piece of software that a package provider manages, and that is stored in a specific package source.
- Windows 10, Windows Server 2016, or down-level Windows OS + WMF5
- Linux or Mac with the PowerShellCore
What you can do with PackageManagement
- Manage a list of software repositories in which packages can be searched, acquired, and installed
- Search and filter your repositories to find the packages you need
- Seamlessly install and uninstall packages from one or more repositories with a single PowerShell command
Now lets see the the cmdlets that PackageManagement provides you, in order to manage software on our systems.
We are able to see the commands that are included in PackageManagement by using the below:
Get-Command -Module PackageManagement
Find-Package– Finds software packages in available package sources.
Find-PackageProvider– Returns a list of Package Management package providers available for installation.
Get-Package– Returns a list of all software packages that have been installed by using Package Management.
Get-PackageProvider– Returns a list of package providers that are connected to Package Management.
Get-PackageSource– Gets a list of package sources that are registered for a package provider.
Import-PackageProvider– Adds Package Management package providers to the current session.
Install-Package– Installs one or more software packages.
Install-PackageProvider– Installs one or more Package Management package providers.
Register-PackageSource– Adds a package source for a specified package provider.
Save-Package– Saves packages to the local computer without installing them.
Set-PackageSource– Replaces a package source for a specified package provider.
Uninstall-Package– Uninstalls one or more software packages.
Unregister-PackageSource– Removes a registered package source.
From PowerShell 5.0 and later, PacakgeManagement is included. You may have to update the module. From the screenshot above we can see that the version that I have installed is 126.96.36.199. Currently the latest stable version is 188.8.131.52. PackageManagement 1.2.0-preview is also available if you would like to install it.
If you already have PackageManagement installed and you want to update your current installation to the latest one, then you need to use
-Force parameter. If you do not use
-Force parameter, it will give you an error that module is already installed.
Install-Module PackageManagement -Force
Trusted and Untrusted Sources
As you can see in the screenshot of
Get-PackageSource above, the sources are not trusted. When you are trying to install as package from an untrusted source, it will ask you to confirm every time you install a package. If you want not to confirm every time you can set the source as trusted. You can do it by using the below:
Set-PackageSource -Name <sourcename> -Trusted
If you want to set a trusted source as untrusted, then you will need to use the below:
Set-PackageSource -Name <sourcename> -Trusted:$false
The above tutorial is a basic information about PackageManagement that can help you manage software packages on computers and servers. It would be good to check it further in order to understand better what you are able to do with it. In related links section you are able to find links with a lot of information related to PackageManagement.
I hope the tutorial about PackageManagement is helpful.
Please let me know your comments and thoughts.
You feedback is appreciated.
- PowerShell Tutorials
- PowerShell Scripts
- about_PackageManagement | Microsoft Docs
- PackageManagement project
- Find-Package – Microsoft Docs
- Find-PackageProvider – Microsoft Docs
- Get-Package – Microsoft Docs
- Get-PackageProvider – Microsoft Docs
- Get-PackageSource – Microsoft Docs
- Import-PackageProvider – Microsoft Docs
- Install-Package – Microsoft Docs
- Install-PackageProvider – Microsoft Docs
- Register-PackageSource – Microsoft Docs
- Save-Package – Microsoft Docs
- Set-PackageSource – Microsoft Docs
- Uninstall-Package – Microsoft Docs
- Unregister-PackageSource – Microsoft Docs