Quick Guide for Using Powershell to Control Apache Cloudstack


Controlling your Cloud environment via the Portal (GUI) is something everyone can do (assuming, of course that you know what you want to accomplish and what options you need to get the most out of your platform). A good cloud platform automates things to the greatest extent possible to help prevent human errors from happening. Automation can also help take full advantage of the scalability and flexibility of a cloud.

In this blog, I’m going to take a bit of a different approach to what most Apache Cloudstack administrators are used to working with. Our Leaseweb engineers usually script their actions on the Cloud using Cloudmonkey, a useful tool that provides all of the features an administrator would need. But instead of using Linux and Cloudmonkey, I want to approach things from a different angle. I will focus on Windows Administrators who are familiar with Powershell, and show what can be accomplished using this tool.

We will begin by connecting to Cloudstack via Powershell, list the current Instances under my account and deploy a new Instance.

The Setup

• My Cloudstack environment consists of an isolated network with a virtual router (providing me DHCP, DNS, NAT, VPN, FW and LB services) with an internal network named “internal.”

• There are several service offerings that Leaseweb provides out of the box, I will use the “S” offering of 1core/1GB RAM. There is only 1 zone available for the cloud in the Netherlands, CSRP01NL so this is the one I’ll use.

• I created some templates in the past that I will use in this example, but I could have used the Leaseweb provided ones.

The Process:

Start your Windows server. I use a Windows 10 VM but any recent Windows 2012R2/2016 should also do the trick, as long as Powershell is installed. Next follow these steps:

1. Download “psCloudstack” from GitHub https://github.com/schubergphilis/psCloudstack and place the psCloudStack files in correct folder:


cd .\Documents\WindowsPowerShell\modules\

2. Set the correct execution policy to allow this script to run under the current user:

Set-ExecutionPolicy RemoteSigned -Scope currentuser

3. Import the Cloudstack API module:

Import-Module psCloudstack

4. Set the Leaseweb Cloudstack API endpoint configuration with the keys of the Cloudstack user you want to connect with. In my case, I created a user ‘peter’ and generated keys in the CS GUI.

add-CSConfig -server csrp01nl.leaseweb.com -apikey -<APIkey> -secret <secretkey> -useSSL -SecurePort 443 -UnsecurePort 80

(Note: fill in the correct key values)

5. Check if the created config is correct:


If you made a mistake with the config, remember to close the powershell window and restart a new console because the variables are kept in memory during the same session.

Having completed the previous step, let’s now see which API commands from Cloudstack are available to us:

Get-command -module psCloudstack.

This gives an extensive list of all possible API functions. For reference, the Apache Cloudstack API documentation can be found at: http://cloudstack.apache.org/api/apidocs4.8/TOC_Domain_Admin.html

Now it’s time to do some testing to see if everything works. I’ll start by listing all virtual machines in my domain and under my account:

listVirtualMachines | select name,state,cpunumber,memory

That works, so now let’s deploy a new virtual machine in my network ‘internal’. This requires me to provide the size of the Instance (service offering) and on which template it should be based.

First get the network details of ‘internal’, then the service offering ‘S’, template:

listTemplates -templatefilter self | select name,id

Commands to execute to get all required details:

$netw=listnetworks -name internal

$so=listServiceOfferings -name S

$templ=listTemplates -templatefilter self -name “U1404-64b-10GB”

$zid=listzones -name CSRP01

Deployvirtualmachine -displayname “Peter’s VM” -name PeterVM -networkids $netw.id -serviceofferingid $so.id -templateid $templ.id -zoneid $zid.id

Great! Now, we have an Instance deployed. Let’s see if it’s running and if we can access the console.

And the console:

Start-CSConsoleSession -Server PeterVM

So now we see it is running and the console is working successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *