Using Powershell Packagemanager (OneGet) basics

One of the new great features of WMF5, included in Windows 10 RTM is Powershell Packagemanager (previously called OneGet).

I will not go into the details on how it works or what it is (that you can find here!) I do want to show you how you can use it to simply install some packages from the powershell gallery, or from chocolatey which is basically a community based package source that already includes alot of applications and tools.

Lets take a look at the basic command sets:
Find-Package: find the package you are looking for in the registered package sources in powershell packagemanager
Get-Package: finds the packages on your system that have been installed using powershell packagemanager
Install-Package: installs a package on your system using powershell packagemanager
Uninstall-Package: removes a package from your system that was installed using powershell packagemanager

When you first kick off find-package you may get the request that the package provider nuget has not been installed and needs to be downloaded and installed.

The provider 'nuget v2.8.5.127' is not installed.
nuget may be manually downloaded from https://oneget.org/nuget-anycpu-2.8.5.127.exe and installed.
Would you like PackageManagement to automatically download and install 'nuget' now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

If you select Yes, you will now (by default) get a list of available packages -from the powershell gallery only-.

Lets now install the chocolatey package provider so that we can use PowerShell Packagemanager to install available community packages.

PS C:\Users\Administrator> get-packageprovider -name chocolatey

The provider 'chocolatey v2.8.5.130' is not installed.
chocolatey may be manually downloaded from https://oneget.org/ChocolateyPrototype-2.8.5.130.exe and installed.
Would you like PackageManagement to automatically download and install 'chocolatey' now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"):

If you now once again do a find-package you will suddenly see alot of additional packages that are available from the source ‘chocolatey’. Please be aware however that not all of these packages can be trusted (please read the chocolatey FAQ)

You can install simply the packages by using the install-package, or pipe the install package behind the find-package to also install the dependencies (if any). For example:

Install-package -Name 'GoogleChrome'
Find-Package 'GoogleChrome' -IncludeDependencies | Install-Package

After the software has been installed you can review the installed software by using get-package

Get-Package -Name 'GoogleChrome'

Name                           Version          Source           Summary
----                           -------          ------           -------
GoogleChrome                   45.0.2454.101    C:\Chocolatey...

Here is an example script that you can use for installing some software to your local desktop with powershell packagemanager: oneget_example.ps1

I hope you can enjoy this new functionality as much as myself. This new functionality could greatly help with package deployment and management in the future. You could for example set up your own package repository and deploy your own internal packages using Nuget Server.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.