Bootstrap a Google Cloud Engine (GCE) Windows VM to install Chocolatey

On GCE (Google Cloud Engine) we can choose to specify a start up script that will run when our instance boots up, restarts or both.

We can used a script located on our local computer or a script stored on Google Storage (or other URL) to install Chocolatey (or any other application).

One interesting feature of GCE is that we have 3 options to choose when we run the bootstrap script (you can choose .bat, .cmd or .ps1 files):

1. Before the Sysprep.
2. After the Sysprep.
3. After the Sysprep and in every restart.

 

1. Create a PowerShell Script to Install Chocolatey

First we need to create a PowerShell file to install Chocolatey.

The example below will download and install Chocolatey first and then use Chocolatey to install Adobe Acrobat (nothing fancy here!)

Set-ExecutionPolicy Unrestricted -force
(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')))>$null 2>&1
(gc C:ProgramDatachocolateychocolateyinstallchocolatey.config).replace("true","false") | sc C:ProgramDatachocolateychocolateyinstallchocolatey.config
choco install adobereader -y>$null 2>&1

 

2. Install Google Cloud SDK

Download the SDK from https://cloud.google.com/sdk and then Next, Next, Next.

 

3. Login into GCE

Type the following command on Google Cloud SDK Shell:

gcloud auth login --no-launch-browser

Copy the URL generated on your favorite Internet Browser and the copy the code generated back to SDK Shell.

4. Select you project

Select you project using the following command on Google Cloud SDK Shell:

gcloud config set project valid-project-12345

 

5. Create the VM

Run the following command to create the VM:
gcloud compute instances create "gcekopic01"
--image windows-2008-r2
--zone "europe-west1-d"
--machine-type "g1-small"
--metadata "gce-initial-windows-user=kopiadmin" "gce-initial-windows-password=S3cur3P@ssw0rd"
--metadata-from-file sysprep-oobe-script-ps1="D:/KopiCloud/GCE-Chocolatey-Adobe.ps1"
--boot-disk-type "pd-standard"
--boot-disk-device-name "gcekopic01"

The output will be internal and external IP addresses and the status: