VMware Cloud Community
StephenMoll
Expert
Expert
Jump to solution

vApp Scripting

I note that PowerCLI only has the following commandlets to manage vApps:

  • Export-VApp
  • Get-VApp
  • Set-VApp
  • Import-VApp
  • New-VApp
  • Remove-VApp
  • Start-VApp
  • Stop-VApp

What none of these commandlets seem to offer is a way of manipulating the vApp "Start Order".

Is the vSphere Web Client the only way to set a vApp Start Order?

Or are there any APIs that can allow us to set the start order through scripts?

Tags (2)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Seems I was wrong with that, you can change the start order of VMs in a vApp.

Quick example: simple vApp with 3 VMs in there. The default Start Order

start1.jpg

With the following snippet I cam change that to 2 start groups

$vAppName = 'vApp1'

$vapp = Get-VApp -Name $vAppName

$vmOrder = @(

    @{

        Group = 1

        VM = @('VM2','VM3')

    },

    @{

        Group = 2

        VM = @('VM1')

    }

)

$spec = New-Object VMware.Vim.VAppConfigSpec

$spec.EntityConfig = $vapp.ExtensionData.VAppConfig.EntityConfig

foreach($group in $vmOrder){

    $spec.EntityConfig | where{$group.VM -contains $_.Tag} | %{

        $_.StartOrder = $group.Group

    }

}

$vapp.ExtensionData.UpdateVAppConfig($spec)

And the start order is now exactly as we specified in $vmOrder

start2.jpg


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

11 Replies
daphnissov
Immortal
Immortal
Jump to solution

According to an old response from LucD​, it wasn't possible to change this with PowerCLI. I don't think much has changed there.

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Is PowerCLI representative of all APIs then?

In other words is it true to say, "If you can't do it in PowerCLI, then don't bother looking elsewhere like vCenter API"?

Seems a bit odd, it makes automated/scripted deployments difficult.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Seems I was wrong with that, you can change the start order of VMs in a vApp.

Quick example: simple vApp with 3 VMs in there. The default Start Order

start1.jpg

With the following snippet I cam change that to 2 start groups

$vAppName = 'vApp1'

$vapp = Get-VApp -Name $vAppName

$vmOrder = @(

    @{

        Group = 1

        VM = @('VM2','VM3')

    },

    @{

        Group = 2

        VM = @('VM1')

    }

)

$spec = New-Object VMware.Vim.VAppConfigSpec

$spec.EntityConfig = $vapp.ExtensionData.VAppConfig.EntityConfig

foreach($group in $vmOrder){

    $spec.EntityConfig | where{$group.VM -contains $_.Tag} | %{

        $_.StartOrder = $group.Group

    }

}

$vapp.ExtensionData.UpdateVAppConfig($spec)

And the start order is now exactly as we specified in $vmOrder

start2.jpg


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

daphnissov
Immortal
Immortal
Jump to solution

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Ah! I had just returned with something I had found, which I believe amounts to the same thing...

https://vwiki.co.uk/vApp_Script_Extracts_and_Examples

This is good, I shall pass this to my developers and get them going with this.

Cheers all!

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Should I be able to do this via other APIs?

vSphere API?

I understand some of the management code is developed in C#.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The API methods stay the same, you just need to call them from the C# framework.
They can use the PowerShell script as a prototype :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

StephenMoll
Expert
Expert
Jump to solution

If I have more than one VM in a start order group, and I have "waitingForGuest" set to True, will vCenter wait until all VMs in the group are detected as started via VMTools before moving onto the next group or just the first one?

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

I have been told that VMs using PCoIP or Blast cannot have their desktop connections brokered when they are part of a vApp, is this true?

Google is simply coming with too many hits for me to quickly find anything that confirms or denies this.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, I assume that WaitingForGuest will mean that all VMs in that group have to be detected, before the next group will be started.

I don't know if VMs in a vApp, that use PCOIP, can not be brokered.

You could ask in the Horizon community?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Yup! I think I will.

0 Kudos