NoteIf you are not familiar with package managers I recommend you read first the short Chocolatey package manager tutorial at our sister site Windows Eight Forums as an introduction to this tutorial: Chocolatey - Install Apps from Command Line. Although written for Windows 8 the tutorial can be used without any modifications in Windows 10.
InformationApril 2014 Microsoft presented the Windows Management Framework V5 Preview. Although aimed to IT professionals as a tool in managing networks in corporate infrastructure, parts of it will make the life a bit easier to us normal geeks.
From my personal point of view the most interesting and intriguing part of Windows Management Framework V5 Preview is a new Windows PowerShell module PackageManagement. Please notice: PackagaManagement was originally named and known as OneGet. All mentions of PowerShell OneGet here at Ten Forums and elsewhere on the Internet refer to PowerShell PackageManagement as it is known today.
Windows 10 Technical Preview is the first Windows version to have native built-in PackageManagement in its PowerShell and PowerShell ISE tools, Build 9926 being the first build PackageManagement works out-of-the-box.
Garret Serack, head of the PackageManagement development team in his MSDN blog:
(Source: http://blogs.msdn.com/b/garretts/arc...0-preview.aspx)For those tuning in for the first time, let me shine some light on exactly what we're buildin'.PackageManagement is a Package Management Aggregator -- it's basically a core module that anyone can write a plugin (what we call Providers) and creates a consistent interface for software discovery, installation and inventory. On the one side of this core module, is a set of PowerShell Cmdlets that let the user work with all these different package management systems, and on the other is the interface for writin' package providers.
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.
We've started a list of all the package providers that we'd like to see built. Some will be built by Microsoft, some by third parties. Over time I'd expect that there's gonna be quite a number.
In not-so-geek language, the PS PackageManagement is kind of management system, collecting various package managers (see Part One: Some vocabulary below) under one umbrella. Using PS PackageManagement user can search applications in repositories maintained by these package managers, install them, update and uninstall them. To support user's own network he / she can even build own repository from where the users of said network can download and install applications.
Feel free to post in this thread and ask you questions whether about functionality issues and errors, about a basic function you did not understand because I explained it in a confusing way , or about more advanced features not covered by this tutorial.
I will update this tutorial regularly. Currently we are using Build 9926.
PowerShell PackageManagement :
Senior Open Source Engineer Garrett Serack:
First a simple introduction video showing PowerShell PackageManagement in action. If you have quarter of an hour time, I recommend you watch it to get PS PackageManagement in a nutshell:
Part One: Some vocabulary
Part Two: PowerShell PackageManagement Module
Part Three: Install Chocolatey package provider
Part Four: Search and Install a Package (application)
Part Five: Search and Install multiple Packages (applications)
Part Six: Use GridView to Search and Install Packages (applications)
A short list of terms you should know before starting:
- Package Manager
- A collection of software tools that automates the process of installing, upgrading, configuring, and removing software packages for a computer's operating system in a consistent manner. It typically maintains a database of software dependencies and version information to prevent software mismatches and missing prerequisites (source: Wikipedia)
- Package managers like apt-get are widely used for software installation and distribution in Linux world, NuGet brought the method to Windows, Chocolatey took it a step further. PoweShell PackageManagement is direct continuation to them in evolution of Windows Package Management, acting as an aggregator for all available package managers
- A software package is a software that has been built from source with one of the available package management systems. The package is typically provided as compiled code, with additional meta-information such as a package description, package version, or "dependencies". The package management system can evaluate this meta-information to allow package searches; to perform automatic upgrades to a newer version; to check that all dependencies of a package are fulfilled and/or to fulfill them automatically by installing missing packages (source: Wikipedia)
- A software repository is a storage location from which software packages may be retrieved and installed on a computer (source: Wikipedia)
- In this tutorial we will use Chocolatey repository to install applications
- PowerShell is a native Windows automation and configuration management tool, it works with familiar command line tools as well as with NET Framework based scripting language (source: Wikipedia)
- PowerShell recognizes all command line commands but as it can much more than Command Prompt, it in my opinion, from a normal user's point of view could be called Command Prompt v.2
- PowerShell ISE
- Windows PowerShell Integrated Scripting Environment (ISE) is the big brother of PowerShell
- From Microsoft: "Windows PowerShell ISE is a host application that enables you to write, run, and test scripts and modules in a graphical and intuitive environment. Key features in Windows PowerShell ISE include syntax-coloring, tab completion, Intellisense, visual debugging, Unicode compliance, and context-sensitive Help. It provides a rich scripting experience"
- PowerShell cmdlet
- Cmdlets (pronounced command-lets) are specialized commands in the PowerShell environment that implement specific functions (source: Wikipedia)
- A cmdlet has usually a verb-noun syntax, for instance in this tutorial we use cmdlets like Find-Package and Install-Package
- PowerShell Script
- Windows PowerShell includes a dynamically typed scripting language which can implement complex operations using cmdlets imperatively (source: Wikipedia)
- Pipe or Pipeline
- PowerShell implements the concept of a pipeline, which enables the output of one cmdlet to be piped as input to another cmdlet (source: Wikipedia)
- A pipe character ('|') is used to tell a cmdlet its output will be sent to another cmdlet as input. For example in this tutorial we will first search for a certain package (application) and then pipe it to a cmdlet which installs the package. Here we search for a package named AdobeReader and pipe it to another cmdlet to be installed:
Code:Find-Package -Name AdobeReader | Install-Package
2.1) To start search and open the PowerShell or PowerShell ISE (I prefer ISE but you can do everything in this tutorial with either of them):
PackageManagement adds 10 cmdlets to PowerShell, we can list them with cmdlet Get-Command telling it that we would like to get a list of PackageManagement module's cmdlets (#1 in screenshot below):
Code:Get-Command -Module PackageManagement
(Click screenshots to enlarge. Please notice some screenshots might show module name OneGet, the former name of PackageManagement.)
2.3) Some cmdlets can be used without parameters or piping their output to other cmdlets. For instance to check which repositories we have available we can use the PackageManagement cmdlet Get-Packagesource (#2 in screenshot above in step 2.2).
NoteNotice that as you have not installed any package providers yet, the cmdlet Get-Packagesource might give an error if given now. Install the provider Chocolatey as told in Part Three before testing this cmdlet.
2.4) If we want the output of a cmdlet in a file or to be used as input (data source) on another cmdlet we simply add a pipe to do that. See #3 in screenshot above in step 2.2 about how to send the list of all available packages in our repositories to cmdlet Out-GridView which as its name already hints presents its input in a grid view table:
Code:Find-Package | Out-GridviewTipThe GridView output in PowerShell cannot be saved, only viewed as long as the window is open. Luckily there's a very practical pipe to work around this obstacle, Clipboard (clip) pipe. You can use | clip to send the output directly to Windows Clipboard and paste it from there to any text editor, word processor or other program that accepts paste from Clipboard. For example the above piping in step 2.4 could be done as Find-Package | clip to send the list of packages to Clipboard.
It can be used with any command or cmdlet that outputs text:
- dir C:\Windows | clip copies the list of files and folders in C:\Windows to clipboard
- ipconfig | clip sends your network configuration info to clipboard
Notice that piping to Clipboard also works in Command Prompt.
3.1) By default the Chocolatey repository we want to use is not available and as the package list in step 2.4 shows we have quite a modest amount of packages available.
We want to add the Chocolatey repository with its 3,800+ packages (full list and package search: Chocolatey Gallery | Packages
). In order to be able to do that we have to have unrestricted rights to run PowerShell scripts. These rights are determined by Execution Policy. There are four level of execution policy rights:
- Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode
- AllSigned - Only scripts signed by a trusted publisher can be run
- RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run
- Unrestricted - No restrictions; all Windows PowerShell scripts can be run
Let's first check our current execution policy and if it is not Unrestricted, let's change that. The cmdlet to check your execution policy:
The cmdlet to change it to Unrestricted with necessary parameters:Code:Get-Executionpolicy
Code:Set-Executionpolicy Unrestricted -Scope CurrentUserNoteThe -Scope CurrentUser parameter is not needed if you are running PowerShell as administrator.
Accept the policy change with Yes. If you want to you can check that the policy was changed with another Get-Executionpolicy cmdlet.
3.2) With unrestricted rights to run scripts we can now add the Chocolatey repository with command Get-Packageprovider Chocolatey:
3.3) Now we can create a complete list of all packages and pipe it to XML export cmdlet to be saved as an XML file on our local computer and when ready, check with an import cmdlet that the list really was created. Command to export the list and save it on computer is (select any location you want to, I saved the list in file D:\Test.xml.):
As the file will be huge, this takes some time. Get coffee, walk a bit, call your mother. When back by your computer and the file is created, import it and pipe to GridView to read it and see which packages are available. Command is:Code:Find-Package | Export-CliXML D:\Test.xml
Code:Import-CliXML D:\Test.xml | Out-GridView
An actual up-to-date list of packages in Chocolatey repository also available at https://chocolatey.org/packages.
4.1) As you already know you can search all available packages with Find-Package cmdlet and pipe it to GridView tool with | Out-GridView or to Clipboard to be pasted in another program with | clip.
4.2) You can always check which packages are already installed on your system with cmdlet Get-Package:
4.3) Let's install Adobe PDF Reader. First we search to be sure the package is available. Searching for Adobe finds all packages where the word Adobe is part of the package name:
Code:Find-Package -Name Adobe
PowerShell asks if we are sure, just answer Yes:Code:Install-Package -Name AdobeReader
TipIf you do not want to be asked if you want to install (above screenshot), you can add the -Force switch to your command:
Code:Install-Package -Name AdobeReader -Force
That's it. Adobe Reader is now installed on your system. No need to go to Adobe site, find download page, reject all "special offers" to install this and that with the software you want to.
WarningBe careful with Install-Package cmdlet! Type the name of the package you want to install exactly as the packagename is shown when you search for it (PowerShell is not case sensitive, it does not matter if you use upper or lower case); if you had now in above example given the cmdlet as Install-Package -Name Adobe, it had installed all 8 packages found with partial name Adobe.
4.4) You can add the -Verbose switch to any cmdlet to see the output if you want to. Here the same Adobe Reader installation with -Verbose (notice that as it was already installed, PackageManagement skipped the installation):NoteBy the way, the above screenshot reveals that I made a mistake regarding the warning I gave in step 4.3; I was stupid enough to ask PackageManagement to install Chrome and it did what I asked, installed all packages where the word Chrome is a partial filename. Instead of getting what I wanted, Google Chrome browser, I got 9 applications installed:
5.1) To install multiple applications with one simple command is in my opinion the best part of using a package manager. To be sure that the packages for programs I want to install, in this example case WinRAR, Skype and Opera are available, I first search for them (separate packages with comma):
All available, now I just need one command to install all three. I search them once again and pipe them to Install cmdlet:Code:Find-Package -Name WinRAR, Skype, Opera
As I was sure I had the names correctly I could have saved some typing and just installed them without searching them first:Code:Find-Package -Name WinRAR, Skype, Opera | Install-Package
Easy! All three programs were installed:Code:Install-Package -Name WinRAR, Skype, Opera
6.1) To see which versions of a certain application are available we can use the -Allversions switch. For instance checking out available Firefox versions we give cmdlet Find-Packages with following parameters:
The above command piped to GridView:Grave Accent sign (`) which for PowerShell acts like the Escape character.Code:Find-Package -Name Firefox -Allversions
First line of the multiline command searches the repositories for all versions of Firefox piping them to GridView (see step 6.1). The second line creates a custom title for GridView, and the third line tells PackageManagement to send (pass through) user selected items from GridView to Install-Package cmdlet.
Now I just select the version I want to and click OK to install it:TipI could have done the above also without GridView by simply adding the -RequiredVersion switch to Install-Package command:
Code:Install-Package -Name Firefox -RequiredVersion 28.0
6.3) Another way to use GridView is to select multiple applications to be installed in GridView, then accept with OK to install all selected packages. To do this we can open the GridView showing all packages, select the packages and install all of them with one click of the OK button. See the multiline command in screenshot below, do not miss those tiny Grave Accents:
NoteThat's it folks! Now you have at least the basics to start working with PackageManagement . Post your questions and issues in this thread.
- How to Reinstall and Re-register All Built-in Windows Apps in Windows 8 and 10
- How to Install Your Apps from My Library in the Store in Windows 10
Kari Tried this tonight and could not get past 3.5 where its import module. Power shell says module not found. Going to give up try again in morning.