Automation with Chocolatey Part 1 – My PCs

I first heard about Choclolatey about a year ago. If you’re not familiar with Chocolatey, it is a package manager for Windows similar to APT or YUM for Linux that allows for command line installation of packages from a repository. For more details, I recommend checking out their about page.  Since everything is command line, including the install of Chocolatey itself, this means you can write scripts to automate these tasks.

Installing Packages

Once Chocolatey is installed, installing packages is as simple opening a Powershell window as an administrator and running something like this:

If you don’t wanted to be prompted to confirm the installation, add -y to the end of that.

I created this script when I built out a new PC to install most of the common software I like to have on a PC.

As you can see, I had to get a little creative with Rufus.  For some reason it does not install in one of the usual locations, and it does not create a shortcut in the start menu.  Fortunately, a little scripting can take care of this.

Automatic Updates

How many times have you launched a program like Notepad++ or Filezilla and the first thing it wants to do is install updates?  With Chocolatey and some minimal scripting, this doesn’t happen anymore.  I created a scheduled task that runs this Powershell script overnight to install updates.

This will update any packages that were installed with Chocolatey, including Chocolatey itself, and dump the results to a text file.  I don’t really need the text file, but it’s nice to have and I like to just spot check it from time to time to make sure everything appears to be working.  Looking at the one from last night, I see that Chocolatey has updated f.lux for me as well as Malwarebytes.

Some programs, when updated, like to put their shortcut on the desktop for all users.  The second line of the script takes care of that.

And if you’re not sure if a software package was installed with Chocolatey or not, run this command and it will list your installed Chocolatey packages:

Packages and More

There are plenty of packages already available for Chocolatey.  And if you know what you are doing, you can create your own.  I don’t know what I’m doing in that regard, and haven’t had a reason (yet) to pursue that.

Since literally everything with Chocolatey can be scripted, I really wanted to give this a go in a domain environment.  For security and reliability reasons and per Chocolatey’s own recommendation, I don’t plan on using Chocolatey in a production environment at this time.  My lab is a different story…

Automation with Chocolatey Part 2 – The Lab (Coming Soon)