PowerShell Version 5, What’s new!

PowerShell native switch configuration

I’m not going to dig into this too deeply, instead, read Jeffrey Snover’s great post on the topic here.

APT-GET comes to PowerShell!

The Coolest new feature is OneGet, which is PowerShell’s adaptation of the community-based software repository Chocolatey.  Chocolatey supports a tremendous catalog of software, allowing you to silently install software directly from the command line.  Some examples of software found in the Chocalatey gallery:

  • 7Zip
  • NotePad++
  • Google Chrome
  • Java
  • Flash
  • VLC Player
  • Microsoft C++
  • Puddy
  • Fiddler
  • DotNet Framework
  • Virtual Box
  • Virtual Clone Drive
  • FoxIT

You can see a full catalog of software here, http://chocolatey.org/packages.

 Sample of using OneGet to install packages

First and foremost, you’ll need to temporarily allow remote script execution in order to use this version of OneGet.  That is because behind the scenes to install a program using OneGet, PowerShell will download a Chocolatey install script and execute it, and if your execution policy prohibits it from running, you won’t be having any fun. To get started, first install WMF 5.0, available here.  This may or may not require a restart for you.  Now, launch PowerShell and check out the version of PowerShell you’re running with Get-Host.

Aw, yeah…Upgrayedd

Now, let’s Import the OneGet module and see what new commands are available. 02   PowerShell exposes some very nice functionality here.  Out of the box, we’re able to add our own corporate PackageSource repository, and do some other interesting things:

Command Purpose
Add-PackageSource Add your own Package Source other than Chocolatey
Find-Package Search your package sources for software
Get-Package Get information about packages installed locally
Get-PackageSource Get a listing of Package Sources available
Install-Package Install a package
Remove-PackageSource Remove a Package Source
Uninstall-Package Uninstall a package from your system

Let’s say that we needed a tool to work with PDFs, and had never heard of Adobe before.  We might run Find-Package, and pipe that into Where-Object to filter.

You could potentially discover software to install from the command line.

Let’s choose Foxit Reader.  Remember when I said to allow script execution?  Well this is why.  If you try to install without specifying this, you’ll get the following error.

The install script can’t run if you don’t allow for UnSigned Scripts during your Install-Package session

This is what is really happening when you use OneGet to install FoxitReader.  PowerShell first downloads the configuration script (C:\Chocalatey\lib\FoxitReader\tools\ChocolateyInstall.ps1) that looks like this:

  Install-ChocolateyPackage 'FoxitReader6010.1213_L10N_Setup.exe' 'EXE' '/quiet' 'http://cdn01.foxitsoftware.com/pub/foxit/reader/desktop/win/6.x/6.0/L10N/FoxitReader6010.1213_L10N_Setup.exe'

Which as you can see, downloads the .EXE from the CDN for the provider, then passes quiet install parameters on to the exe.

EDIT 12/16/2014: As of this writing the problem with Chocolatey packages not installing unless you run with the signing policy as ‘Unrestricted’ has been resolved.  Leaving the below for posterity.

[…]So, hopefully you’ve launched an administrative session of PowerShell and set your execution policy to UnRestricted for the moment.  Assuming you’ve done so, you should see the following when you run your install for 7Zip or FoxitReader.  If you’re not running as an administrative user, you’ll get a UAC prompt, which I personally feel is good behavior, then the install will continue.  Since these scripts are configured by the application owners, some will be silent installs, some will not. 05 For instance, if you run the install of Visual C++ 2010 from an administrative PowerShell prompt, the application will install with no prompt whatsoever. All in all, very powerful stuff, and finally brings App-Get like functionality to PowerShell.  10/10 would download again. EDIT: I’ve noticed that Install-Packages has parameters to pass your switches along to the .exe files, and you can see there are a lot of parameters available.  However, it’s early in the game and as of this writing the help files don’t exist for this and other PowerShell v5 resources.   PARAMETERS -AllVersions   -AllowPrereleaseVersions   -Confirm   -Force   -ForceX86   -Hint <string>   -IgnoreDependencies   -InstallArguments <string>   -InstallationOptions <hashtable>   -LeavePartialPackageInstalled   -LocalOnly   -MaximumVersion <string>   -Metadata <hashtable>   -MinimumVersion <string>   -Name <string[]>   -OverrideArguments   -Package <SoftwareIdentity[]>   -PackageParameters <string>   -Provider <string>   -RequiredVersion <string>   -Source <string[]>   -WhatIf

7 thoughts on “PowerShell Version 5, What’s new!

  1. Zack April 4, 2014 / 7:41 pm

    “Puddy” I think you mean putty ?


  2. luma April 6, 2014 / 3:12 pm

    Is there an equivalent to “apt-get dist-upgrade” to update all installed packages?


    • FoxDeploy April 6, 2014 / 4:00 pm

      Hmm, I’ll have to experiment with this syntax. Currently, you could run get-package and pipe that into one of the other commands, like uninstall package.


  3. Pierre October 11, 2014 / 10:48 am

    Not a mature package yet. I get an error message, which does not help to troubleshoot (I can open http://www.microsoft.com/ in internet explorer, so wtf?)
    find-package : Source location ‘http://www.microsoft.com/’ is not valid for this provider.


    • FoxDeploy October 11, 2014 / 1:53 pm

      Keep in mind that this is the experimental preview release. Currently, oneget is partially disabled due to performance constraints when contacting chocolatey, and has been since the September preview.

      Expect this to work again shortly!


      • pierre November 3, 2014 / 4:10 pm

        experimental ok, but why not give an error message saying that oneget is disabled (and a link to an explanation perhaps), instead of “www.microsoft.com is not valid” (!)


        • FoxDeploy November 3, 2014 / 4:12 pm

          If you try again in the newest release, this should be working again!


Have a code issue? Share your code by going to Gist.github.com and pasting your code there, then post the link here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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