Packaging for the masses - PowerShell

Packaging for the masses - PowerShell

Released in November 2006, Windows PowerShell, quickly became the defacto way to automate tasks on Windows. Whether it was automating the creation of Users within Active Directory, or configuring/maintaining your Exchange Server, PowerShell was the way to do it.

When Chocolatey started, it was clear that PowerShell was going to be at the heart of how it works as well, and that continues to this day.

Within a Chocolatey package, there are three main PowerShell files:

  • chocolateyInstall.ps1
  • chocolateyUninstall.ps1
  • chocolateyBeforeModify.ps1

📝 NOTE Not all of these files are required within every Chocolatey package, as Chocolatey performs a number of tasks automatically, and overrdiing the dfeault functionality is only required when you want to do something different.

When a Chocolatey package is installed/uninstalled, these files are executed at different times, giving a package creator full control over exactly what actions are performed within a package.

This flexibility allows for the creation of simple packages (that simply execute a native installer) all the way up to highly complicated installations that perform several operations.

On top of this, Chocolatey ships with a number of built-in functions, to help with the specific tasks of installing applications, binaries, zips, and scripts.

When you need to create your own custom PowerShell functions, Chocolatey provides the ability to create extension packages, to allow the sharing of code across multiple packages, rather than duplicating it.