Stefan Boos

My personal GitHub pages

Follow me on GitHub

Setting up Virtual Machines Rapidly with Chocolatey

Rationale

As a Mac user I have a virtual machine for my Windows applications (Parallels or in Azure). Every now and then the machine has accumulated so many applications I install for test purposes, that it consumes a large amount of disk space, is slow and the software is outdated. Thus, I destroy the machine regularly and set it up from scratch. In this, the Chocolatey package manager comes in as a great helper. It streamlines the re-installation of my virtual machine.

Recreate a Windows VM

The following shows my steps for recreating virtual Windows machines:

Save the Current State

From your current VM instance …

  1. Export all Chocolatey packages (see below)

  2. Export the list of all Plugins you have installed for your development environments

  3. Remove all the packages from the exported lists, which you don’t need any longer

Note:

At the moment I do not save Application Settings

Setting Up the VM From Scratch

  1. Install the base Windows system from CD (or restore it from a backup)

  2. Install all pending Windows Updates

  3. (Parallels) Install Parallels Tools and activate the shared clipboard

  4. Install Chocolatey

  5. (Azure VM) Install a means to share data with your remote pc, e.g. NextCloud.

  6. Install the Chocolatey packages you have exported previously: choco install packages.config -y

  7. Update all install Chocolatey packages: choco upgrade all

  8. Cleanup: cleanmgr

Finetuning

  1. For Docker-Desktop the Windows Subsystem for Linux is required

Appendix

Export Installed Chocolatey Packages

Hint: Upgrade your chocolatey packages first: choco upgrade all

Easy way: ChocolateyGUI

  1. Install ChocolateyGUI: choco install chocolateygui

  2. Click the Save button to export all installed packages.

Without ChocolateyGUI

Follow the instructions Ammaar Limbada has published on GitHub: alimbada / ExportChocolatey.ps1

#Put this in Export-Chocolatey.ps1 file and run it:
#.\Export-Chocolatey.ps1 > packages.config
#You can install the packages using
#choco install packages.config -y

Write-Output "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Write-Output "<packages>"
choco list -lo -r -y | % { "   <package id=`"$($_.SubString(0, $_.IndexOf("|")))`" version=`"$($_.SubString($_.IndexOf("|") + 1))`" />" }
Write-Output "</packages>"

Interesting Visual Studio Plugins