I’ve been looking at using PowerCLi with vCloud. I use it extensively with vSphere, so how much different can it be? The answer is subtly different. The methods of connecting are similar, but the commands used are reassuringly familiar!
First of all you need to connect to a vCloud Director Server;
Run Connect-CIServer with the server name and valid credentials.
Connect-CIServer -Server cloud.example.com -User ‘MyAdministratorUser’ -Password ‘MyPassword’
To create a vApp from a template
Retrieve the organization vDC to which you want to add the new vApp.
$myOrgVdc = Get-OrgVdc -Name ‘MyOrgVdc’
Retrieve the source vApp template for your new vApp.
$myVAppTemplate = Get-CIVAppTemplate -Name ‘MyVAppTemplate’
Create your new vApp.
$myVApp = New-CIVApp -Name ‘MyVApp’ -VAppTemplate $myVAppTemplate -OrgVdc $myOrgVDC
By default, the vApp is powered off.
Renew the runtime lease for the new vApp and set it to 12 hours.
Set-CIVApp -VApp $myVApp -RuntimeLease “12:0:0″ –RenewLease
To set leases, you can use the days.hours:minutes:seconds syntax.
Start the new vApp.
Start-VApp -VApp $myVApp
Power on all virtual machines in all vApps with names starting with MyVApp.
Get-CIVApp -Name ‘MyVApp*’ | Start-CIVApp
Suspend all virtual machines in all vApps with names starting with YourVApp.
Get-CIVapp -Name ‘YourVApp*’ | Suspend-CIVApp
Power off all virtual machines in the vApp named MyVApp1.
Get-CIVapp -Name ‘MyVApp1′ | Stop-CIVApp
Shut down the guest operating systems of all virtual machines in the vApp named MyVApp2.
Get-CIVapp -Name ‘MyVApp2′ | Stop-CIVAppGuest
Restart the guest operating systems of all virtual machines in the vApp named MyVApp3.
Get-CIVapp -Name ‘MyVApp3′ | Restart-CIVAppGuest
Reset all virtual machines in the vApp.
Get-CIVapp -Name ‘MyVApp4′ | Restart-CIVApp
Retrieve all virtual machines with names starting with MyVM and power them on.
Get-CIVM -Name ‘MyVM*’ | Start-CIVM
Suspend all virtual machines with names starting with YourVM.
Get-CIVM -Name ‘YourVM*’ | Suspend-CIVM
Power off the virtual machine named MyVM1.
Get-CIVM -Name ‘MyVM1′ | Stop-CIVM
Shut down the guest operating system of the virtual machine named MyVM2.
Get-CIVM -Name ‘MyVM2′ | Stop-CIVMGuest
Restart the guest operating system of the virtual machine named MyVM3.
Get-CIVM -Name ‘MyVM3′ | Restart-CIVMGuest
Reset the nonresponsive virtual machine named MyVM4.
Get-CIVM -Name ‘MyVM4′ | Restart-CIVM
Playing around with the PowerCLi vCloud commands make administration of vCloud infrastructure a lot easier and quicker then via the standard GUI, especially if you already utilise PowerCLi for the administration of vSphere.