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('')))>$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 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:

Retrieve the Latest Windows Azure VM Image Name

When we want to create a new Microsoft Azure VM using PowerShell, we need to specify the OS image.

The ImageName parameter is required by New-AzureVMConfig and New-AzureQuickVM cmdlets.

To get a list of all available images, we use the Get-AzureVMImage cmdlet.

This command will return a list of all images and details for each of them.

We can filter the results.

For example: if we want to get the list of all Windows Server 2012 R2 Datacenter images, we can use the following command:

Get-AzureVMImage | where { $_.ImageFamily -eq "Windows Server 2012 R2 Datacenter"}

This command still return several images.

If we want to use list just the last image released we order the images by the PublishedDate property and get the first item of the list.

(Get-AzureVMImage | where { $_.ImageFamily -eq "Windows Server 2012 R2 Datacenter"} |Sort-Object -Descending -Property PublishedDate)[0].ImageName


Install Chocolatey in Amazon AWS Instances

Chocolatey ( is a package manager for Windows (similar to Yum/Apt-Get in Linux) based on NuGet.

Chocolatey is very useful to automate the deployment of Windows applications on the cloud.

We can use AWS instance bootstrap (aka User Data) to install Chocolatey and some applications on our AWS Instances.

Create a PowerShell Script

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

The example below will download and install Chocolatey first and then use Chocolatey to install SQL Server 2012 Express

Bootstrap a Chocolatey script from the AWS Management Console

In the step 3 (configure instance), expand the Advanced Details section.

Click as file option and use the Browse button to select the PowerShell Script.

Bootstrap a Chocolatey script from the AWS EC2 CLI

Open the AWS EC2 CLI console and type:

ec2-run-instances ami-69ae251e -n1 -k AWS-KopiCloud -g sg-b4016ed1 –instance-type t2.micro –subnet sunet-ad8b5ada –user-data-file D:ec2-api-toolsChocolatey-SQl.ps1

The User-Data-File parameter is bootstrap the PowerShell script on the start up of the AWS instance.

If the execution is successful, you will got the AWS Instance ID and more data such IP Address.

More info about parameters and output at

Welcome to KopiCloud

KopiCloud is a blog about Windows and Citrix Automation on the Cloud.

Also, KopiCloud are tools under development to deploy Windows and Citrix servers on multi-cloud environments with few clicks and no code.

This blog is curated by Guillermo Musumeci, Founder and Chief Developer of KopiCloud and CtxAdmTools, a popular site for Windows and Citrix Automation Tools.

Here we will talk about deployment and automation on the Cloud (Amazon AWS, Microsoft Azure and Google Cloud) of Windows and Citrix servers.

Follow us on Twitter @kopicloud to stay tuned of new posts!

Thank you!

Guillermo Musumeci