This content is part of the Essential Guide: Bookmark this expansive guide to DevOps for Windows

Automate Windows configurations with Boxstarter and Chocolatey

Follow this Boxstarter tutorial to install the open source tool, and use it alongside PowerShell, Chocolatey and GitHub gists for streamlined and repeatable Windows configurations.

Setting up a new machine with applications, configurations and updates can be time-consuming. Boxstarter is an open source tool that uses Chocolatey packages and PowerShell to bring up a Windows machine and configure it as an admin wants.

Boxstarter also minimizes disruption from reboots: If a system change, such as a software installation, requires a reboot, Boxstarter performs the reboot and resumes processing its ongoing task. Boxstarter also suspends Windows updates, detects and waits for processes initiated by the msiexec command in Windows Installer to finish, and performs all features remotely via PowerShell and scheduled tasks.

Similar to HashiCorp Vagrant for virtual environment builds, Boxstarter enables IT teams to provide parity between development and production environments for Windows. Since both Vagrant and Boxstarter can run commands and scripts, such as Chocolatey commands, configurations stay consistent from machine to machine, and the developers and admins can even keep them in one configuration file.

Install Boxstarter

Install Boxstarter with the following PowerShell command:

PS C:\Users\vagrant\Documents> . { iwr -useb } | iex; get-boxstarter –Force

This command ensures that the Chocolatey client installs and downloads the Boxstarter PowerShell module onto the local machine. This is the only setup necessary to use Boxstarter.

Boxstarter commands

One of the most useful Boxstarter commands is Install-BoxstarterPackage, which calls Chocolatey packages directly, similar to the choco install command for the Chocolatey package manager. The difference between these commands is Boxstarter's ability to reboot the machine midprocess if necessary and install packages remotely.

To install a particular software component -- such as Google Chrome, in this example -- use the command PS C:\Users\vagrant\Documents> Install-BoxstarterPackage -PackageName googlechrome.

To change Windows Explorer settings, use the command Set-WindowsExplorerOptions.

Display hidden files, folder drives and protected OS files with modifiers, as shown:

PS C:\Users\vagrant\Documents> Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles
[VAGRANT-10]Boxstarter: Setting Windows Explorer options...
[VAGRANT-10]Boxstarter: Restarting the Windows Explorer process...

Boxstarter can also create a package directly from a PowerShell script. The script below performs various tasks: It restarts the w32time service, enables PowerShell remoting, installs Firefox and creates a new local user group:

Restart-Service w32time
choco install firefox -y
Enable-PSRemoting -Force
New-LocalGroup -Name 'dan'

Use the New-PackageFromScript command to create a package from the PowerShell script. This command places the NuGet package in the directory C:\ProgramData\Boxstarter\BuildPackages by default. Next, the Install-BoxstarterPackage command installs the script from the local repository:

PS C:\vagrant> New-PackageFromScript -Source .\newmachine.ps1 -PackageName 'newmachine'
Attempting to build package from 'newmachine.nuspec'.
Successfully created package 'C:\ProgramData\Boxstarter\BuildPackages\newmachine.1.0.0.nupkg'
[VAGRANT-10]Boxstarter: Created a temporary package newmachine from .\newmachine.ps1 in C:\ProgramData\Boxstarter\BuildPackages
[]: PS C:\vagrant> Install-BoxstarterPackage -PackageName newmachine
[VAGRANT-10]Boxstarter: Installing package newmachine
[VAGRANT-10]Boxstarter: Disabling Automatic Updates from Windows Update
[VAGRANT-10]++ Boxstarter starting Calling Chocolatey to install newmachine. This may take several minutes to complete...
[VAGRANT-10]++ Boxstarter finished Calling Chocolatey to install newmachine. This may take several minutes to complete... 00:00:06.9712572
[VAGRANT-10]Boxstarter: Restore Automatic Updates from Windows Update
Errors       : {}
ComputerName : localhost
Completed    : True
FinishTime   : 3/9/2019 10:01:11 AM
StartTime    : 3/9/2019 10:01:03 AM

Set up a new machine from a gist with Boxstarter

Boxstarter enables admins to run a GitHub gist -- a shareable Git repository -- as a package, which is similar to using a PowerShell script. Create a gist with all of the various configurations required to set up a new machine, and then, as needed, point a machine to the gist to install applications and configure the system.

The gist, shown below, sets the time zone and installs Google Chrome, Firefox, Git, Windows Subsystem for Linux, Microsoft's Visual Studio Code source code editor and the Visual Studio Code PowerShell extension. It also customizes the build by disabling Bing search, setting Explorer options, placing the task bar to the bottom of the screen and enabling PowerShell remoting. It updates PowerShell help and installs any pending Windows updates to ready the machine for use. Throughout this process, Boxstarter handles any necessary reboots without disrupting the script execution.

Set-TimeZone -Name "Eastern Standard Time" -Verbose
choco install googlechrome -y
choco install firefox -y
choco install git -y
choco install wsl -y
choco install vscode -y
choco install vscode-powershell -y
Set-TaskbarOptions -Dock Bottom
Set-ExplorerOptions -showHiddenFilesFoldersDrives -showFileExtensions
Enable-PSRemoting -Force

On the local machine, pass the URL to Install-BoxstarterPackage. This step uses the raw, shareable gist URL, as seen in the PowerShell line below:

PS C:\Users\vagrant\Documents> Install-BoxstarterPackage -PackageName ''

Boxstarter is built largely on top of Chocolatey and PowerShell, and its features make it a good fit to configure a single machine setup that admins can then easily replicate. Boxstarter has few limitations in terms of what it can configure on a Windows box, which enables enterprises to set up new machines without the traditional methods, such as Microsoft System Center Configuration Manager and Microsoft Deployment Toolkit.

Dig Deeper on Configuration Management and DevOps