Sunday, August 2, 2015

Setup your Chocolatey repository in Azure - Part 3

PackageManagement (previously referred as OneGet) is a new feature introduced in PowerShell 5.0 to discover and install software packages from around the web. It is a manager or multiplexor of existing package managers (also called package providers) that unifies Windows package management with a single Windows PowerShell interface. With PackageManagement, you can do the following.

Manage a list of software repositories in which packages can be searched, acquired, and installed
Discover software packages you need

Seamlessly install, uninstall, and inventory packages from one or more software repositories
To see the commands supported by PackageManagement, use the Get-Command as given below.

PS C:\> Get-Command -Module PackageManagement | ft -Property Name, Version, Source

Name                     Version Source          
----                     ------- ------          
Find-Package    PackageManagement
Get-Package     PackageManagement
Get-PackageProvider PackageManagement
Get-PackageSource PackageManagement
Install-Package PackageManagement
Register-PackageSource PackageManagement
Save-Package    PackageManagement
Set-PackageSource PackageManagement
Uninstall-Package PackageManagement
Unregister-PackageSource PackageManagement

By default a set of providers with sources are configured in PackageManagement. You can use the Get-PackageSource cmdlet to see the available sources.

PS C:\> Get-PackageProvider | select name


PS C:\> Get-PackageSource -ProviderName Chocolatey | ft ProviderName, IsTrusted, IsRegistered, Location

ProviderName IsTrusted IsRegistered Location                    
------------ --------- ------------ --------                    
Chocolatey       False         True

Each PackageManagement provider may have one or multiple software sources, or repositories. The Get-PackageSource cmdlet can be used to discover what repositories are associated with a provider. For e.g. to see the sources associated with the Chocolatey provider use the cmdlet as given below. The Register-PackageSource cmdlet can be used to add a new source to the existing provider. We'll use this cmdlet to register the Chocolatey source we created in the previous post to the PackageManagement provider as given below.

PS C:\> Register-PackageSource –provider Chocolatey –name AzureChoco –location

Name                             ProviderName     IsTrusted  IsRegistered IsValidated  Location                                                        
----                             ------------     ---------  ------------ -----------  --------                                                         
AzureChoco                       Chocolatey       False      True         True                    

PS C:\> Get-PackageSource -ProviderName Chocolatey | ft ProviderName, IsTrusted, IsRegistered, Location

ProviderName IsTrusted IsRegistered Location                                   
------------ --------- ------------ --------                                   
Chocolatey       False         True              
Chocolatey       False         True  

We’ve successfully registered our Chocolatey repository to the source, we can now find and install packages using the PackageManagement as  given.

PS C:\> Find-Package -Source AzureChoco | ft Name, Version, source

Name Version Source   
---- ------- ------   
Foxe 1.2.0   AzureChoco

No comments: