VMware Cloud Community
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Setting properties of VMs in a vApp

I have a few vApps with 25 VMs each in vCloud Director and would like to set a few properties to on / off with PowerCLI as the gui is a mission. These options include:

Set "Enable guest customization" to yes, "Change SID" to no and "Password Reset" to no.

I looked at the avaliable command-lets with "get-command -Module vmware.vimautomation.cloud" but I see nothing that allows manipulation of a VMs in a vApp.

Would I be able to make these changes with PowerCLI?

Thanks!

1 Solution

Accepted Solutions
alanrenouf
VMware Employee
VMware Employee
Jump to solution

We havent given any dates as to when the cmdlets for manipulating objects will be available but as mentioned in this thread by Luc, you can use the Get-CIView or .ExtensionData to manipulate the API.

Unfortunatly I do not have the infrastructure to test this at the moment but could you try something like this:

$CIvApp = Get-CIVApp Domain01
Foreach ($CIVM in ($CIvApp | Get-CIVM)) {
    $GuestCustomization = $CIVM.ExtensionData.Section | Where {$_.GetType() -like "*GuestCustomizationSection"}
    $GuestCustomization.Enabled = $true
    $GuestCustomization.ChangeSid = $true
    $GuestCustomization.ResetPasswordRequired = $false
    $GuestCustomization.UpdateServerData()
}

Domain01 is the name of my vApp

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com

View solution in original post

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

Those features you are looking for are not yet available through cmdlets.

But you can use the API methods to make changes.

Have for example a look at Jake's post called vCloud API/GUI Throwdown: Part 2, to see how this could be done.


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

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Any idea how long before per VM / vApp manipulation command-lets show face?

Thanks for the tip but I'm trying to keep all my automation tasks in PowerCLI scripts, for the team's benefit. Easier for others to pick up on Power CLI than learning C#.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No clue about dates, I don't work for VMware.

But Jase's code is definitely PowerCLI/PowerShell , not C# :smileygrin:


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

RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can use the API methods from PowerCLI. You don't need C# to do that.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
alanrenouf
VMware Employee
VMware Employee
Jump to solution

We havent given any dates as to when the cmdlets for manipulating objects will be available but as mentioned in this thread by Luc, you can use the Get-CIView or .ExtensionData to manipulate the API.

Unfortunatly I do not have the infrastructure to test this at the moment but could you try something like this:

$CIvApp = Get-CIVApp Domain01
Foreach ($CIVM in ($CIvApp | Get-CIVM)) {
    $GuestCustomization = $CIVM.ExtensionData.Section | Where {$_.GetType() -like "*GuestCustomizationSection"}
    $GuestCustomization.Enabled = $true
    $GuestCustomization.ChangeSid = $true
    $GuestCustomization.ResetPasswordRequired = $false
    $GuestCustomization.UpdateServerData()
}

Domain01 is the name of my vApp

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Wow fantastic alanrenouf! That code works 100%!

That ExtensionData looks pretty powerful! Is it possible to get a list of all the methods/functions I can perform with it?

Thanks for the help gentlemen Smiley Happy

Reply
0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Glad that worked.

You can do a Get-Member on the Extensionfata property to get the Methods and Properties like so:

$VM = Get-CIVM VM1

$VM.ExtensionData | Get-Member

I also use PowerGUI or any other script editor debugger to explore the varaibes and look at the information.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

So trying to do the same sort of thing to edit the network settings for a vm in a vApp but it's not working:

$CIvApp = Get-CIVApp VMNAME
Foreach ($CIVM in ($CIvApp | Get-CIVM)) {
    $network = $CIVM.ExtensionData.Section | Where {$_.GetType() -like "*networkConnectionSection"}

# Now running $network.NetworkConnection I get a list of properties. I would like to change these:

#Network                      : VM Network
#NeedsCustomization      : True
#NetworkConnectionIndex  : 0
#IpAddress                       :
#ExternalIpAddress            :
#IsConnected                  : False
#MACAddress                   : 00:50:56:b8:04:57
#IpAddressAllocationMode  : DHCP
#AnyAttr                            :
#VCloudExtension              :

$Network.NetworkConnection.NeedsCustomization = $false
$Network.NetworkConnection.IsConnected = $true
$Network.NetworkConnection.IpAddress = "192.168.1.22"
$Network.UpdateServerData()  

}

Error I get is: "Property 'XXXXXXXXXXXXXXXXXXX' cannot be found on this object; make sure it exists and is settable."

Question now is if I can see the values there why can I not adjust them? Is my syntax incorrect?

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast
Jump to solution

Nevermind, got it.

Foreach ($vm in $CIVM)) {
    $Net= $vm.ExtensionData.Section | Where {$_.GetType() -like "*networkConnectionSection"}

    $Network = $Net.NetworkConnection[0]

    $Network.Network = "Network Name"
    $Network.NeedsCustomization = $true
    $Network.IsConnected = $true
    $Network.IpAddress = "192.168.1.22"
    $Network.IpAddressAllocationMode = "MANUAL"
    $Net.UpdateServerData()
}

Can also do this, same thing:

Foreach ($vm in $CIVM)) {

    $Network = ($vm.ExtensionData.Section | where {$_ -is [VMware.VimAutomation.Cloud.Views.NetworkConnectionSection]}).NetworkConnection[0]

    $Network.Network = "Network Name"
     $Network.NeedsCustomization = $true
     $Network.IsConnected = $true
     $Network.IpAddress = "192.168.1.22"
     $Network.IpAddressAllocationMode = "MANUAL"

    ($vm.ExtensionData.Section | where {$_ -is [VMware.VimAutomation.Cloud.Views.NetworkConnectionSection]}).updateServerData()

}

Sorry if I'm rambling on Smiley Happy Hopefully someone finds this useful in the future...

edho
Contributor
Contributor
Jump to solution

This was very useful for us! I would like to send my greatest thanks for this information. It solved one of our challenges really nice.

Reply
0 Kudos
edho
Contributor
Contributor
Jump to solution

Hi All and CSIEnvironments.

This worked really fine with vCD v1.5, but we have upgraded vCD to v5.5 and i have some issues with a VM that has multiple NICs.

The example code is:

Foreach ($vm in $CIVM)) {
    $Net= $vm.ExtensionData.Section | Where {$_.GetType() -like "*networkConnectionSection"}

    $Network = $Net.NetworkConnection[0]

    $Network.Network = "Network Name 1"

    $Network.NeedsCustomization = $true

    $Network.IsConnected = $true

    $Network.IpAddressAllocationMode = "DHCP"

    $Network = $Net.NetworkConnection[1]

    $Network.Network = "Network Name 2"
    $Network.NeedsCustomization = $true
    $Network.IsConnected = $true
    $Network.IpAddressAllocationMode = "DHCP"

    $Network = $Net.NetworkConnection[2]

    $Network.Network = "Network Name 3"

    $Network.NeedsCustomization = $true

    $Network.IsConnected = $true

    $Network.IpAddressAllocationMode = "DHCP"


    $Net.UpdateServerData()
}

This used to work but not any more. It chooses the networks randomly even if i points out the network name. Lookong forward to get some help on this.

I would like to get more info about the settings that can be used and whats they do, ie the parameter "$Network.NetworkConnectionIndex", anyone?

Reply
0 Kudos
Dean_H
Contributor
Contributor
Jump to solution

Hi,

The NetworkConnectionIndex determines which nic is which. So a network card with the NetworkConnectionIndex of 0 is the first nic on the box, 1 is the second nic etc... If you have multiple nics you will need to evaluate through all of them like so:

$civms = (get-civapp dean* | get-civm)

foreach ($civm in $civms) {

    $Net = $civm.ExtensionData.Section | Where {$_.GetType() -like "*networkConnectionSection"}

    $nics = $Net.NetworkConnection

    foreach ($nic in $nics) {

  if ($nic.NetworkConnectionIndex -eq 0) {

  $nic.Network = "Network Name 1"

  $nic.NeedsCustomization = $true

  $nic.IsConnected = $true

  $nic.IpAddressAllocationMode = "DHCP"

  }

  if ($nic.NetworkConnectionIndex -eq 1) {

  $nic.Network = "Network Name 2"

  $nic.NeedsCustomization = $true

  $nic.IsConnected = $true

  $nic.IpAddressAllocationMode = "DHCP"

  }

  if ($nic.NetworkConnectionIndex -eq 2) {

  $nic.Network = "Network Name 3"

  $nic.NeedsCustomization = $true

  $nic.IsConnected = $true

  $nic.IpAddressAllocationMode = "DHCP"

  }

  if ($nic.NetworkConnectionIndex -eq 3) {

  $nic.Network = "Network Name 4"

  $nic.NeedsCustomization = $true

  $nic.IsConnected = $true

  $nic.IpAddressAllocationMode = "DHCP"

  }

  }

  $Net.UpdateServerData()

}

Cheers,

CSIEnvironments aka Dean

Blog: http://mypowercli.wordpress.com | Twitter: @Danger0u5
Reply
0 Kudos
edho
Contributor
Contributor
Jump to solution

Thanks Dean

I made it like this to get it working:

Foreach ($vm in $CIVM)) {

    $Net= $vm.ExtensionData.Section | Where {$_.GetType() -like "*networkConnectionSection"}

    $Network = $Net.NetworkConnection[0]

    $Network.NetworkConnectionIndex = 0

    $Network.Network = "Network Name 1"

    $Network.NeedsCustomization = $true

    $Network.IsConnected = $true

    $Network.IpAddressAllocationMode = "DHCP"

    $Network = $Net.NetworkConnection[1]

    $Network.NetworkConnectionIndex = 1

    $Network.Network = "Network Name 2"

    $Network.NeedsCustomization = $true

    $Network.IsConnected = $true

    $Network.IpAddressAllocationMode = "DHCP"

    $Network = $Net.NetworkConnection[2]

    $Network.NetworkConnectionIndex = 2

    $Network.Network = "Network Name 3"

    $Network.NeedsCustomization = $true

    $Network.IsConnected = $true

    $Network.IpAddressAllocationMode = "DHCP"

    $Net.UpdateServerData()

}

Have you found any detailed documentation about theese parameters and other API parameters that can be altered?

With Regards

Eddie

Reply
0 Kudos