• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    PowerShell
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ChocolateyGet provider allows to download packages from Chocolatey.org repository via OneGet

Build status

ChocolateyGet

ChocolateyGet is a Package Management (OneGet) provider that facilitates installing Chocolatey packages from any NuGet repository.

Install ChocolateyGet

Install-PackageProvider ChocolateyGet -Force

Note: Please do not use Import-Module with Package Management providers, as they are not meant to be imported in that manner. Either use Import-PackageProvider or specify the provider name with the -Provider argument to the PackageManagement cmdlets, such as in the examples below:

Sample usages

Note: When ran for the first time, any of the subsequent commands will install Chocolatey if not already present in your system. Run them in an elevated shell, otherwise the installation will fail.

Search for a package

Find-Package -Provider ChocolateyGet -Name nodejs

Find-Package -Provider ChocolateyGet -Name firefox*

Install a package

Find-Package nodejs -Verbose -Provider ChocolateyGet | Install-Package

Install-Package -Name 7zip -Verbose -Provider ChocolateyGet

Get list of installed packages

Get-Package nodejs -Verbose -Provider ChocolateyGet

Uninstall a package

Get-Package keepass-plugin-winhello -Provider ChocolateyGet -Verbose | Uninstall-Package -Verbose -RemoveDependencies

Manage package sources

Register-PackageSource privateRepo -Provider ChocolateyGet -Location 'https://somewhere/out/there/api/v2/'
Find-Package nodejs -Verbose -Provider ChocolateyGet -Source privateRepo | Install-Package
Unregister-PackageSource privateRepo -Provider ChocolateyGet

ChocolateyGet integrates with Choco.exe to manage and store source information

Pass in choco arguments

If you need to pass in additional package installation options, you can use either the dedicated package parameter and argument properties or the combined AdditionalArguments property.

Install-Package sysinternals -Provider ChocolateyGet -AcceptLicense -AdditionalArguments '--paramsglobal' -PackageParameters '/InstallDir:c:\windows\temp\sysinternals /QuickLaunchShortcut:false' -InstallArguments 'MaintenanceService=false' -Verbose
Install-Package sysinternals -Provider ChocolateyGet -AcceptLicense -AdditionalArguments '--paramsglobal --params "/InstallDir:c:\windows\temp\sysinternals /QuickLaunchShortcut:false" -y --installargs MaintenanceService=false' -Verbose

DSC Compatibility

Fully compatible with the PackageManagement DSC resources

Configuration MyNode {
	Import-DscResource -Name PackageManagement,PackageManagementSource
	PackageManagement ChocolateyGet {
		Name = 'ChocolateyGet'
		Source = 'PSGallery'
	}
	PackageManagementSource ChocoPrivateRepo {
		Name = 'privateRepo'
		ProviderName = 'ChocolateyGet'
		SourceLocation = 'https://somewhere/out/there/api/v2/'
		InstallationPolicy = 'Trusted'
		DependsOn = '[PackageManagement]ChocolateyGet'
	}
	PackageManagement NodeJS {
		Name = 'nodejs'
		ProviderName = 'ChocolateyGet'
		Source = 'privateRepo'
		DependsOn = '[PackageManagementSource]ChocoPrivateRepo'
	}
}

Keep packages up to date

To update a package, simply run Install-Package again, and the provider will update the package to the latest version.

If you specify a version with either the -RequiredVersion or -MaxiumVersion parameters and a qualifying version of the package is available, the provider will upgrade the package to that version.

To return a list of all installed packages that qualify for an update:

Get-Package -ProviderName ChocolateyGet | Select-Object Name, Version, @{l="LatestVersion";e={(Find-Package $_.Name -Provider $_.ProviderName).Version}} | Where-Object {$_.Version -lt $_.LatestVersion}

ChocolateyGet also has a reserved keyword 'latest' that, when passed as a Required Version, compares the version of package currently installed against what is in the repository. This can be used to check whether the latest version of package is already installed.

# In this example, version 7.68 is the latest available
Find-Package curl -Provider ChocolateyGet

Name                           Version          Source           Summary
----                           -------          ------           -------
curl                           7.68.0           chocolatey

# Install an older version
Install-Package curl -RequiredVersion 7.60.0 -Provider ChocolateyGet -Force

Name                           Version          Source           Summary
----                           -------          ------           -------
curl                           v7.60.0          chocolatey

# Get-Package returns no results, because the 'latest' version (ex: 7.68) is not installed
Get-Package curl -RequiredVersion latest -Provider ChocolateyGet
Get-Package : No package found for 'curl'.
At line:1 char:1
+ Get-Package curl -RequiredVersion latest -Provider ChocolateyGet
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage

This feature can be combined with a PackageManagement-compatible configuration management system (ex: PowerShell DSC LCM in 'ApplyAndAutoCorrect' mode) to regularly keep certain packages up to date:

Configuration MyNode {
	Import-DscResource -Name PackageManagement
	PackageManagement ChocolateyGet {
		Name = 'ChocolateyGet'
		Source = 'PSGallery'
	}
	PackageManagement SysInternals {
		Name = 'sysinternals'
		RequiredVersion = 'latest'
		ProviderName = 'ChocolateyGet'
		DependsOn = '[PackageManagement]ChocolateyGet'
	}
}

Please note - Since Chocolatey doesn't track source information of installed packages, and since PackageManagement doesn't support passing source information when invoking Get-Package, the 'latest' functionality will not work if Chocolatey.org is removed as a source and multiple custom sources are defined.

Furthermore, if both Chocolatey.org and a custom source are configured, the custom source will be ignored when the 'latest' required version is used with Get-Package.

Example PowerShell DSC configuration using the 'latest' required version with a custom source:

Configuration MyNode {
	Import-DscResource -Name PackageManagement,PackageManagementSource
	PackageManagement ChocolateyGet {
		Name = 'ChocolateyGet'
		Source = 'PSGallery'
	}
	PackageManagementSource ChocoPrivateRepo {
		Name = 'privateRepo'
		ProviderName = 'ChocolateyGet'
		SourceLocation = 'https://somewhere/out/there/api/v2/'
		InstallationPolicy = 'Trusted'
		DependsOn = '[PackageManagement]ChocolateyGet'
	}
	PackageManagementSource ChocolateyRepo {
		Name = 'Chocolatey'
		ProviderName = 'ChocolateyGet'
		Ensure = 'Absent'
		DependsOn = '[PackageManagement]ChocolateyGet'
	}
	# The source information wont actually be used by the Get-Package step of the PackageManagement DSC resource check, but it helps make clear to the reader where the package should come from
	PackageManagement NodeJS {
		Name = 'nodejs'
		ProviderName = 'ChocolateyGet'
		Source = 'privateRepo'
		RequiredVersion = 'latest'
		DependsOn = @('[PackageManagementSource]ChocoPrivateRepo', '[PackageManagementSource]ChocolateyRepo')
	}
}

If using the 'latest' functionality, best practice is to either:

  • use the default Chocolatey.org source
  • unregister the default Chocolatey.org source in favor of a single custom source

Known Issues

Compatibility

ChocolateyGet works with PowerShell for both FullCLR/'Desktop' (ex 5.1) and CoreCLR (ex: 7.0.1), though Chocolatey itself still requires FullCLR.

When used with CoreCLR, PowerShell 7.0.1 is a minimum requirement due to a compatibility issue in PowerShell 7.0.

Users must upgrade to v4.1.0 or higher of this provider module prior to the release of Chocolatey v2 to ensure continued compatibility.

Save a package

Save-Package is not supported with the ChocolateyGet provider, due to Chocolatey not supporting package downloads without special licensing.

Package search with MaximumVersion / AllVersions return unexpected results

Due to a bug with Chocolatey versions 0.10.14 through 0.10.15, ChocolateyGet is unable to search packages by package range via command line as of version 2.1.0. Please upgrade Chocolatey to version 0.11.0 or higher to correct this issue.

Legal and Licensing

ChocolateyGet is licensed under the MIT license.