Posh-ChocoBear Module

Filed under: PowerShell

Installing Chocolatey is straight forward and simple till you need to add feeds and install it a different location for both the install and the tools directory.

Then you need to create a script that handles all that unless you want to repeat those steps for each installation. After a while, even the script gets in the way.

I put a module on the PowerShellGallery for wrapping Chocolatey commands in PowerShell and to extend it.

Additionally, I added two functions that installs Chocolatey. Install-ChocoBear installs Chocolatey and the choco-bear myget.org feed, while Install-Chocolatey just focuses on Chocolately.

The two commands comes with 3 parameters for custom installs:

  • -Path for setting the $Env:ChocolatelyInstall variable
  • -ToolsDirectory for settings the $Env:ChocolateyToolsLocation variable
  • -Feeds takes a hastable of feed names and feed URLs to add custom feeds to chocolatey.
    • If you put a pipe character, | in the URL string and follow it with the -u and -p parameters, the commands will know to use that as the username and password args.
    • .e.g -Feeds @{“feed1” = “https://www.myget.org/F/choco-bear/api/v2|-u="name” -p="pw“”}
Set-ExecutionPolicy Unrestricted -Scope Process
Install-Package Posh-ChocoBear -Force
Install-Module Posh-ChocoBear
Install-Chocolatey -Path "c:\apps" -Feeds  @{"choco-bear" = "https://www.myget.org/F/choco-bear/api/v2|"}

It only downloads Chocolatey if it is not already installed and it will force it to upgrade. The other thing I’m working on with it is looking for a configuration file. If one exists, then it will use that to pick the install location and feeds to add.

This way, you could have a config file in your OneDrive folder that helps streamline a particular setup on all your machines.



Nerdy Mishka