In this blog I will introduce you to some of the basic functionality of using PowerCLI with vCloud.
The most recent version of VMware PowerCLI is available in the PowerShell Gallery so you can install the PowerCLI with one command:
Install-Module VMware.PowerCLI -Scope CurrentUser
And then load the module for vCloud:
Import-Module -Name VMware.VimAutomation.Cloud
When I loaded the module I ran into the following error message:
I fixed this by changing the execution policy for running scripts in Powershell like so:
Do take note of the warning message when changing the policy and make sure you run Powershell as an administrator before running the above command.
Now that we have installed and loaded the module lets see what we got:
Please be aware that not all Cmdlets can be run as a Organization Administrator, some need to be run as vCloud administrator.
Now lets get started with some of the basics.
Connect to you vCloud tenant
Connect-CIServer –Server <vdc FQDN> –Org <org_name>
Enter your credentials when prompted and voila you are connected to your tenant.
Listing vApp’s and VM’s inside a vApp
Let’s starts with listing a vApp called ‘Test”’ and the VM’s within that vApp.
Get-CIVApp -name Test | Get-CIVM
Listing vApp’s in a catalog
Now lets see if we can get some information about vApp’s stored in the vCloud catalog
Get-Catalog | Get-CIVAppTemplate
*In a next blog post I will show you how to deploy a vApp from the catalog.
Ok now that we have used some basic commands lets turn it up a nudge and see if we can play around with a vApp network.
PowerCLI beyond the basics
Creating a Isolated network for a vApp
New-CIVAppNetwork -VApp Test -Name 'MyVAppInternalNetwork' -Routed -Gateway '192.168.2.1' -Netmask '255.255.255.0'
And if we look in vCloud we will find an isolated network with the name ‘MyVAppInternalNetwork’ has been created:
Of course, if you can add a network you can also remove it again:
Get-CIVAPP -name test | Get-CIVAppNetwork -Name 'MyVAppInternalNetwork' | Remove-CIVAppNetwork
So there you have it, PowerCLI and vCloud.
Please be aware that not everything can be done with PowerCLI, at some point you will need to start using the REST API for more advanced automation needs.
More info on vCloud REST API can be found here here https://code.vmware.com/apis/722
Check our other vCloud Director related articles here
6,997 total views, 32 views today