PowerShell PackageManagement (OneGet) - Install Apps from Command Line  

Page 1 of 14 12311 ... LastLast
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line

    PowerShell PackageManagement (OneGet) - Install Apps from Command Line

    How to Use PowerShell PackageManagement to Install Desktop Apps in Windows
    Published by Category: Installation & Upgrade
    25 Apr 2016
    Designer Media Ltd

    Note   Note
    If 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.

    information   Information
    April 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:

    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.
    (Source: OneGet (it’s in the Windows 10 Preview!) – Garrett Serack: Open Source Development at Microsoft)

    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 :
    GitHub - OneGet/oneget: PackageManagement (aka OneGet) is a package manager for Windows
    PowerShell OneGet (@PSOneGet) on Twitter


    Senior Open Source Engineer Garrett Serack:
    http://blogs.msdn.com/b/garretts/
    https://twitter.com/fearthecowboy


    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:



     Contents:

    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)




    Part One

     Some vocabulary


    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

    • Package
      • 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)

    • Repository
      • 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
      • 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




    Part Two

     PowerShell PackageManagement Module



    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):
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2015-02-04_07h22_21.png

    2.2) PackageManagement is a built-in integrated module in PowerShell. A module when added to PowerShell adds its cmdlets to common cmdlet "library", meaning that we can use the cmdlets without specifically telling PowerShell it's a PackageManagement cmdlet.

    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
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_01h03_00.png
    (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).
    Note   Note
    Notice 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-Gridview
    Tip   Tip
    The 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.





    Part Three

     Install Chocolatey package provider


    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:
    Code:
    Get-Executionpolicy
    The cmdlet to change it to Unrestricted with necessary parameters:
    Code:
    Set-Executionpolicy Unrestricted -Scope CurrentUser
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_17h28_48.png

    Note   Note
    The -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:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2015-02-04_07h27_28.png

    Notice that adding Chocolatey, the provider NuGet will also be added.

    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.):
    Code:
    Find-Package | Export-CliXML 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:
    Import-CliXML D:\Test.xml | Out-GridView
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_05h32_01.png

    You can import this list and pipe it to GridView tool whenever you want to. You can of course also open it outside the PowerShell with any program capable of handling XML files like Microsoft Excel. List will change constantly as more and more packages will be added to repositories, remember to replace the list file regularly with the Export-CliXML cdmlet as told above.

    An actual up-to-date list of packages in Chocolatey repository also available at https://chocolatey.org/packages.





    Part Four

     Search and Install a Package (application)


    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:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_02h43_47.png

    Don't forget that as with any command or cmdlet with text output you can pipe it to GridView or Clipboard or export as XML file.

    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 PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_02h26_17.png

    The search found 8 files, among them the one we wanted, the AdobeReader package. We can now install it with command:
    Code:
    Install-Package -Name AdobeReader
    PowerShell asks if we are sure, just answer Yes:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_02h27_30.png

    Tip   Tip
    If 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.
    warning   Warning
    Be 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):
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_02h32_18.png

    4.5) You can delete the installer file with Uninstall-Package cmdlet, here uninstalling AdobeReader:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_02h38_37.png

    4.6) You can also search a package and pipe it directly to Install-Package cmdlet:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_02h59_34.png

    Note   Note
    By 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:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_03h07_56.png

    I would like to maintain what's left of my reputation and explain that I did it with purpose to show what the warning in step 4.3 means, but to be totally honest that was an accident .




    Part Five

     Search and Install multiple Packages (applications)


    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):
    Code:
    Find-Package -Name WinRAR, Skype, Opera
    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 | Install-Package
    As I was sure I had the names correctly I could have saved some typing and just installed them without searching them first:
    Code:
    Install-Package -Name WinRAR, Skype, Opera
    Easy! All three programs were installed:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_03h26_01.png




    Part Six

     Use GridView to Search and Install Packages (applications)


    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:
    Code:
    Find-Package -Name Firefox -Allversions
    The above command piped to GridView:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_03h31_05.png

    6.2) Let's use the GridView to do the same in a creative way:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_03h44_06.png

    To make the command more readable I have separated different parts of it to their own respective lines. To tell PowerShell that a command continues on the next line I need to use the Grave Accent sign (`) which for PowerShell acts like the Escape character.

    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:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_03h53_27.png

    Firefox version 28 was now installed:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_03h56_08.png

    Tip   Tip
    I 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:
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-10-31_04h41_50.png

    Note   Note
    That's it folks! Now you have at least the basics to start working with PackageManagement . Post your questions and issues in this thread.

    Kari






  1. Posts : 719
    win 7 dual boot / 10
       #1

    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.
      My Computer


  2. Posts : 17,661
    Windows 10 Pro
    Thread Starter
       #2

    Charlie said:
    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.
    Please don't shoot the messenger, I have to tell you this although I know you will not like to hear it: That is most definitely a user error. If the replacement OneGet.psd1 module is where the user tells it to be, it will be found and installed. You did not forget to extract the ZIP file first?

    See the screenshot below. First command line, after I extracted the ZIP packet to a folder I copied the folder on root of my D: drive, gave the Import Module command and it was installed successfully (# 1 in screenshot). Then I copied the the folder to desktop, again no error messages, successfully installed (# 2).

    Last (# 3) I made a typo, removed one letter from the folder name Desktop. Now I get that error message, Module not found because PowerShell cannot find a location named as I typed it.

    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-11-01_06h03_09.png

    It works for 100% sure if you first do as told in 3.3 (extract the ZIP packet), then 3.4 (run the unblocker script) and finally give the IPMO command exactly as told in 3.5.

    Kari
      My Computer


  3. Posts : 719
    win 7 dual boot / 10
       #3

    Charlie said:
    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.
    Kari. You are right. My mistake was that I was not typing in the right path to my getone folder. I was pasting your code in then changing the drive letter and username but I failed to change the destination folder name to OneGet-2426796. Which is what my folder was named after extracting the zip file. So moving on. I will post my next goof soon ha! Charlie
      My Computer


  4. Posts : 17,661
    Windows 10 Pro
    Thread Starter
       #4

    Charlie said:
    Kari. You are right. My mistake was that I was not typing in the right path to my getone folder.
    One reason why I prefer the ISE version of PowerShell is its "Command & Text Predicting". Start typing, ISE shows what's possible. Click the image to see it in action :).

    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-ps_textinput.gif
      My Computer


  5. Posts : 719
    win 7 dual boot / 10
       #5

    That's cool I will try that. Also been getting tripped up by this packet instead of package. step 4.3 have a look.

    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-Packet -Name Adobe
    Charlie
      My Computer


  6. Posts : 17,661
    Windows 10 Pro
    Thread Starter
       #6

    Charlie, thanks! That's a bad typo, my apologies. Fixed.

    OneGet does not handle packets, it should always be package. Please let me know about each and every typo you'll find, also if my non-native English sounds comical and you would like me to change an expression to be more understandable :).
      My Computer


  7. Posts : 17,661
    Windows 10 Pro
    Thread Starter
       #7

    Got a message from a user trying to install Adobe Shockwave Player, getting an error telling there are several providers (repositories) with the same package.

    The solution is simple, use the -ProviderName switch and tell which repository you want to use:

    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-11-01_23h20_19.png
      My Computer


  8. Posts : 17,661
    Windows 10 Pro
    Thread Starter
       #8

    New OneGet experimental build released, tutorial (step 3.2) updated:

      My Computer


  9. Posts : 17,661
    Windows 10 Pro
    Thread Starter
       #9

    Weekly OneGet developer online meeting just finished, really interesting. Everybody can join the weekly meetings Fridays at 10 AM PST / 19:00 (7 PM) CET. Follow @PSOneGet in Twitter, meeting link tweeted the meeting day 30 to 60 minutes before the meeting.
    PowerShell PackageManagement (OneGet) - Install Apps from Command Line-2014-11-14_20h36_58.png
      My Computer


 

Tutorial Categories

PowerShell PackageManagement (OneGet) - Install Apps from Command Line Tutorial Index Network & Sharing Instalation and Upgrade Browsers and Email General Tips Gaming Customization Apps and Features Virtualization BSOD System Security User Accounts Hardware and Drivers Updates and Activation Backup and Restore Performance and Maintenance Mixed Reality Phone


  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:01.
Find Us




Windows 10 Forums