In this tutorial, you will learn how to install software automatically for Windows through the command line, using Chocolatey. This year, it feels like I've spent a lot of my time helping clients automate their deployment processes. Cloud servers are definitely gaining traction nowadays. When you are spinning up virtual servers, you will not want to manually install software on them. When we work with cloud servers, we want to be able to install and update everything automatically. Within your Ci/Cd pipeline, it is very common to have a Build Environment build step before the Deploy step is executed. One of my favourite tools at the minute is called Chocolatey. Chocolatey is a package manager for Windows. Chocolatey does the same thing that Nuget does, just for WIndows applications. Chocolatey has thousands of packages and I bet most of your favourite software programs can be installed via Chocolately ๐Ÿ”ฅโ˜€๏ธ๐ŸŒŠ๐Ÿ’™

Chocolatey is not only useful for build servers, you can also use it to install software on your own PC. As a contractor, I need to set up development environments on a regular basis. Being able to automate my new PC set-up process, saves me about a weeks worth of effort every year. If you work as a manager of other developers, just think how much time your team can save by simply automating this stuff.

A recent client brought new laptops for the whole team (10-12 people) halfway through the project. The time it took for each developer to setting up their environment wasted months worth of man-days combined. If we had run a Chocolatey script we could have easily claimed two weeks' of time back into the sprint just by automating it all. If only I knew about Chocolatey at the time ๐Ÿ˜ž๐Ÿ–ค๐ŸŒง๏ธIf you're like me, someone who's been using PC's for years, you will likely find setting up a new environment to be extremely boring and tedious. If you want to learn how to prevent this boredom, read on!

โ„นโ„นโ„น To ensure that I always have access to my Chocolately script, I store them in Dropbox. This means that when I want to set up a new environment, I install Dropbox first, then I open a normal command prompt, navigate to the Dropbox folder, run a setup batch file. This file configures IIS, installs programs and sets permissions!

How To Get Started With Chocolately

You will primarily be working with Chocolately within a Powershell terminal. So open up a Powershell prompt, in admin mode. This is important otherwise programs might not install. Let us first start by looking at my start-up batch file. The first script I use is called setUpPC.ps1. By default, Windows is configured to prevent Powershell scripts from executing. The first step is to enable the script execution so it can, download and install Chocolately and add it to the environment list. The script then calls three additional scripts:

The first script I use is called configureiis.ps1. This script enables IIS automatically as well as enables all the features I need for development. This script looks like this:

The next script is called installApps.ps1. It will install all the programs. Theย '-Y' parameter at the end means Chocolatey won't prompt you to confirm the installation automatically:

You'll obviously want to configure this script to suit your own needs. To browse for packages, go here. Lastly, I call a script to set any Windows configuration. This is done in a script called 'configureWindows.ps1'. At the minute, this script sets Chrome as the default browser:

That's it! If you add all of these scrips into a folder and open a normal command prompt in administrator mode. Simply running setup.bat will configure IIS, install applications, and configure Windows. All within maybe 15 minutes. That's a lot quicker than the several hours it used to take before!

Chocolatey Take Away

I'm hoping after reading this you can see the possibilities of using Chocolatey. It's pretty simple to install and start using and it has a ton of packages available within its marketplace for you to use. It's not just built servers that you should think about automating, your developer and personal PCs can all be automated easily. Happy Coding ๐Ÿค˜