Automating Windows environments’ setup with Boxstarter and Chocolatey packages


image

Talking last week with Scott Hanselman he showed me in his laptop some cool stuff which is very useful for me as I usually need to re-install my machines pretty often due to the release of new betas and the fact that I prefer to start with clean machines whenever I can. And you know, every time you have a new machine or .VHD, you need to re-install a lot of different tools and apps. It is not just about Visual Studio and Office, and sometimes you forget the list of all the apps you need.

So, in a different page, I usually use .VHDX to boot Windows natively (Check this blog post “Booting Windows 8.1 Update natively from a .VHDX image” that I wrote) and it is very convenient as I have like rollback Windows images so I can come back to a baseline, but in any case, after going back to a previous baseline the .VHDX image will usually still have to have quite a few programs to be re-installed manually, like Adobe PDF Reader, Chrome, fiddler, Live Blog Writer, etc. Even more, I might need to install different physical machines so they have different .VHDs to set up…

This is when this stuff that Scott was telling me comes to action, so you can install a list of your most common programs/apps for your Windows machine in an automated way thanks to Boxstarter and Chocolatey packages. Chocolatey packages are nothing but a PowerShell script wrapped as a Nuget package per application that I want to install.

Basically, with Boxstarter you have repeatable, reboot resilient Windows environment installations made easy using Chocolatey packages.

Bottom line, I just have to run BoxStarter by providing my applications’ list and all the software I require will be installed in an automated way!

Here are the steps I followed.

Step 1 – Compose my installation script

You could directly provide the package/application to be installed directly in the URL, like in the following line in the console command prompt:

START http://boxstarter.org/package/skype,fiddler4  (or directly putting the URL in IE with no “START”, Note that this will not work on Chrome or Firefox unless you have a "Click-Once" extension)

But as soon as you have quite a few applications to be installed and with custom setup, you might want to have an installation script, so the following procedure is a better way. 

This is simply a text file (.txt) where you can specify Windows configuration plus all the applications you want to install. The following is part of my own installation script:

BoxStarter_Script.txt

Set-ExplorerOptions -showProtectedOSFiles -showFileExtensions

Enable-RemoteDesktop

cinst adobereader

cinst google-chrome-x64

cinst imageresizerapp

cinst skype

cinst f.lux 

cinst WindowsLiveWriter

cinst sysinternals

cinst git

cinst git.install

cinst Microsoft-Hyper-V-All -source windowsFeatures

cinst IIS-WebServerRole -source windowsfeatures

But rather than just storing that .TXT file somewhere in a drive or USB pen drive, so it is a risk as I could lose it, what I’m doing is to store that .TXT file online as a Gist in GitHub, so it is always available to me when using BoxStarter (since I need Internet Access in any case). You can create your own Gist in your GitHub account, it is super simple, as shown below.

image

You can get the URL (permalink) to your script by pressing the “Raw” button, so you’ll get something like:

https://gist.githubusercontent.com/CESARDELATORRE/2c330905cd96eXXXXX/BoxStarter_CESARDL_Script.txt

That is the URL of your script you need to provide to BoxStarter in order to install your applications.

IMPORTANT: Take into account that whenever you change the content of your GIST .txt file, the URL (permalink) will change, since you have a different URL per versión. So, if you change the list, you NEED to get the new URL.

Step 2 – Run the Script

So! here is how you run BoxStarter and you get all your software installed!

Execute the following command (specifying your own script .TXT file), in a Windows Console:

START http://boxstarter.org/package/nr/url?https://gist.githubusercontent.com/CESARDELATORRE/2c3b3e_YOUR_URL_a71e/BoxStarter_Script.txt

image

It will download BoxStarter thru INTERNET EXPLORER and Click-Once deployment and start executing the setup Process:

image

You can see below how it is installing Google Chrome, for instance:

image

What applications are available as Chocolatey packages?

Like I said, you install the applications thru Chocolatey packages which are nothing but a PowerShell script wrapped as a Nuget package per application that I want to install. Sure, you can create your own packages, but usually you’d like to go on the fast lane and use the already published packages. There are many available already. You can check the list out right here:

https://chocolatey.org/packages

image

For instance, this is the Office 365 Pro Plus package:

https://chocolatey.org/packages/Office365ProPlus

You can add it to your list by writing:

cinst office365proplus

Or for Visual Studio 2013 Ultimate RTM:

https://chocolatey.org/packages/VisualStudio2013Ultimate 

(Check this URL to install optional features in VS 2013)

cinst visualstudio2013ultimate

or with optional features:

cinst VisualStudio2013Ultimate -InstallArguments "Blend LightSwitch OfficeDeveloperTools SQL WebTools Win8SDK WindowsPhone80"

Resources

For deeper info, check the following resources:

http://www.boxstarter.org/

http://boxstarter.org/WhyBoxstarter

https://chocolatey.org/

ScottHa 2014 Tool list, including BoxStarter, etc. http://www.hanselman.com/blog/ScottHanselmans2014UltimateDeveloperAndPowerUsersToolListForWindows.aspx

Comments (6)

  1. Rudi Larno says:

    "I personally prefer to install most of the software on the "by default path" (you'll face less risks.. 😉 ) and use a different partition or disk for my data."

    @Cesar: I've been advocating the use of vhd's as data disks a number of years.

    I just create a new dynamic vhd(x) for each project (or client) and assign it a drive letter (e.g. G:) So all CLI interaction becomes really easy. It is also easy to move the data from one windows setup (a native boot vhd, or hyper-v, azure …) to the next one. And super easy to take backups, or get some rapid GB of storage on my SSD back. (Just copy a currently unused vhd to memory-stick or external SSD)

    I usually use Disk Management (Windows Key, type 'part', enter) because I tend to forget the CLI diskpart statements.

    Since it's native in Windows (7+) it is very easy to set up, the only drawback is that you need a script (or the excellent vhdattach tool) to have the disk auto-attach when you reboot the machine.

    http://www.jmedved.com/vhdattach

  2. Petr says:

    It is high security risk install packages from net under admin account…

  3. John Dunagan says:

    Thanks for this introduction to boxstarter, Cesar. Since I'm looking at the purchase of a new laptop or Surface, this is going to come in very handy.

    (btw, you have Skype in there twice.)

  4. Cesar says:

    @Michael Check this at Chocolatey packages info:

    github.com/…/CreatePackages  

    The default installation path of your .msi/.exe setup file

    The original creator probably had a reason for choosing a specific default installation path.

    If you think, the user should be able to customize this path and you, the package maintainer, know how to pass a custom path on to the installer, then you should use  %ChocolateyBinRoot%

    So it depends on the package. If it doesn't provide an optional parameter, you'd need to modify the package.

    I personally prefer to install most of the software on the "by default path" (you'll face less risks.. 😉 ) and use a different partition or disk for my data.

  5. Michael says:

    Can you choose where the programs install? I have my OS on an SSD and tend to install my programs to separate my mechanical drive.

  6. Francisco Suárez says:

    Very useful and interesting. Thank You!.

Skip to main content