Install/Uninstall OneGet specific version package

As you may know, Windows Framework Management 5 is out as a preview, for already two weeks. Sadly, i didn’t have much free time lately so i can only talk about it now. But let’s have a look about the killer feature of this new version of PowerShell !

Microsoft clearly choose the correct direction for enhancing PowerShell and the fresh wind blowing in the Redmond firm, in the cloud competition, providing applications as easily as OneGet is a powerfull change !

Many great bloggers had already publish posts about how to use OneGet here by Boe Prox or here by François Xavier Cat, but none of them talked about how to install a specific version of a OneGet package. Here is how do this.

Installation

First of all, let’s look about how works the Find-Package.

Get-Help Find-Package
NAME
    Find-Package

SYNTAX
    Find-Package [[-Name] <string[]>] [-Source <string[]>] [-RequiredVersion <string>] [-MinimumVersion <string>]
    [-MaximumVersion <string>] [-Provider <string>] [-Metadata <hashtable>] [-AllowPrereleaseVersions] [-AllVersions]
    [-LocalOnly] [-Hint <string>] [-LeavePartialPackageInstalled]  [<CommonParameters>]

Let’s look about all Putty versions availables…

Find-Package -AllVersions -Name putty
Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61             Available        chocolatey     PuTTY is a free implementation of ...
putty                            0.61.1           Available        chocolatey     PuTTY is a free implementation of ...
putty                            0.62             Available        chocolatey     PuTTY is a free implementation of ...
putty                            0.62.0.1         Available        chocolatey     PuTTY is a free implementation of ...
putty                            0.62.0.2         Available        chocolatey     PuTTY is a free implementation of ...
putty                            0.63             Available        chocolatey     PuTTY is a free implementation of ...
putty                            0.63.0           Available        chocolatey     PuTTY is a free implementation of ...

Hmmm, well, we’ll install the 0.61 version of Putty !

Find-Package -RequiredVersion 0.61 -Name putty
Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61             Available        chocolatey     PuTTY is a free implementation of ...

I won’t explain about how works Install-Package cmdlet has it’s alreay explained in the links provided in this post.

Find-Package -RequiredVersion 0.61 -Name putty | Install-Package -Verbose
Installing Package 'putty' from untrusted source
WARNING: This package source is not marked as safe. Are you sure you want to install software from 'chocolatey'
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
VERBOSE: Performing the operation "Install Package" on target "putty".
VERBOSE: CreateFolder Success:C:\Chocolatey\lib
VERBOSE: NuGet:GET http://chocolatey.org/api/v2/Packages(Id='putty',Version='0.61')
VERBOSE: NuGet:GET http://chocolatey.org/api/v2/package/putty/0.61
VERBOSE: NuGet:Installing 'putty 0.61'.
VERBOSE: NuGet:Successfully installed 'putty 0.61'.
VERBOSE: GetChocolateyWebFile:putty => http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
VERBOSE: Downloading:'http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe' to
'C:\Chocolatey\lib\putty.0.61\tools\putty.exe'
VERBOSE: Installation Successful:putty
VERBOSE: CreateFolder Success:C:\Chocolatey\bin

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61             Installed        chocolatey     PuTTY is a free implementation of ...

let’s install another version of putty to check how OneGet works with multiple versions of a software which have the same folder installation.

Find-Package -RequiredVersion 0.61.1 -Name putty | Install-Package -Verbose
Installing Package 'putty' from untrusted source
WARNING: This package source is not marked as safe. Are you sure you want to install software from 'chocolatey'
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
VERBOSE: Performing the operation "Install Package" on target "putty".
VERBOSE: NuGet:GET http://chocolatey.org/api/v2/Packages(Id='putty',Version='0.61.1')
VERBOSE: NuGet:GET http://chocolatey.org/api/v2/package/putty/0.61.1
VERBOSE: NuGet:Installing 'putty 0.61.1'.
VERBOSE: NuGet:Successfully installed 'putty 0.61.1'.
VERBOSE: InstallChocolateyZipPackage:putty
VERBOSE: CreateFolder Success:C:\Users\Administrator\AppData\Local\Temp\2\Microsoft.OneGet.Utility\1\chocolatey\putty
VERBOSE: GetChocolateyWebFile:putty => http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip
VERBOSE: Downloading:'http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip' to
'C:\Users\Administrator\AppData\Local\Temp\2\Microsoft.OneGet.Utility\1\chocolatey\putty\puttyinstall.zip'
VERBOSE:
GetChocolateyUnzip:C:\Users\Administrator\AppData\Local\Temp\2\Microsoft.OneGet.Utility\1\chocolatey\putty\puttyinstall
.zip
VERBOSE: CreateFolder -- Already Exists:C:\Chocolatey\lib\putty.0.61.1
VERBOSE: Taking Snapshot:C:\Chocolatey\lib\putty.0.61.1\tools
VERBOSE: CreateFolder -- Already Exists:C:\Chocolatey\lib\putty.0.61.1\tools
VERBOSE: Diffing Snapshot:C:\Chocolatey\lib\putty.0.61.1\tools
VERBOSE: Package Successfully Installed:putty

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61.1           Installed        chocolatey     PuTTY is a free implementation of ...

Take a look at the following lines exctracted from the install verbose logs

VERBOSE: Taking Snapshot:C:\Chocolatey\lib\putty.0.61.1\tools
VERBOSE: CreateFolder -- Already Exists:C:\Chocolatey\lib\putty.0.61.1\tools
VERBOSE: Diffing Snapshot:C:\Chocolatey\lib\putty.0.61.1\tools

This is here because a zip is downloaded not an *.exe file.

OneGet

 

Both versions are installed, everything looks good here.

Uninstallation

To list your installed packages, you just have to use the Get-Package cmdlet

Get-Help Get-Package
NAME
    Get-Package

SYNTAX
    Get-Package [[-Name] <string[]>] [-Provider <string>] [-Metadata <hashtable>]  [<CommonParameters>]

It seems Get-Package doesn’t handle versioning.. too bad… Because Get-Package cmdlet return this property when it list packages installed..

Get-Package
Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61             Installed        Local File     PuTTY is a free implementation of ...
putty                            0.61.1           Installed        Local File     PuTTY is a free implementation of ...

Ok, so to uninstall a specific version of our putty, use this:

Get-Package | ? Version -eq '0.61.1' | Uninstall-Package -verbose
VERBOSE: Performing the operation "Uninstall Package" on target "putty".
VERBOSE: Removing Package:C:\Chocolatey\lib\putty.0.61.1

Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61.1           Not Installed
VERBOSE: Current Process is:Elevated

Ok our package putty version 0.61.1 is now uninstalled.

Get-Package
Name                             Version          Status           Source         Summary
----                             -------          ------           ------         -------
putty                            0.61             Installed        Local File     PuTTY is a free implementation of ...

I hope you’ll find utilities with using OneGet.

Regards

Usefull links about One Get: