Is there a VMware Web Services API command to change the VLAN assigned to a Virtual Nic on a Virtual Machine in VMware

erlythornton
erlythornton used Ask the Experts™
on
Hello,

I am looking for a way to change the Virtual LAN that is assigned to a Virtual Network card in a Virtual Machine.  Currently we are starting up our VMs from templates that already have a NIC card assigned to a Virtual LAN.  There are however multiple LANs available in VCenter.  I am looking to see if there ia a command available in the Web Services SDK for VMware where I can dynamically instruct the Virtual Machine I started from that template to change the LAN it's Nic card is attached to.    If not the Web Services API is there another solution where this can be done?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Andrew Hancock (VMware vExpert / EE Fellow)VMware and Virtualization Consultant
Fellow 2018
Expert of the Year 2017

Commented:
vSphere Web Access to Virtual Center, allows control of virtual machines, but unfortunately it does not allow you to change network interface network.

The same is also true of vCenter Mobile Access, that does not require vSphere vCenter but does require vCMA.

This is probably possible in using PowerCLI scripts.

Author

Commented:
Can you elaborate on the PowerCLI scripts?  Can you point me to the reference to this type or similar type of action and perhaps some example code?
VMware and Virtualization Consultant
Fellow 2018
Expert of the Year 2017
Commented:
Using the PowerCLI and tools, lots of additional functions are available like disconnecting CDROM drives from VMs. One of the simplest PowerCLI examples, and something which is actually extremely useful on its own, is the Get-VM cmdlet. Which lists VMs.

I would recommend using the following, also VMware recommends the use of PowerCLI, which is PowerShell interface with vSphere-specific additions.

http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli

PowerCLI can be a bit overwhelming to use,  But it can be enhanced with a nice toolset and a library of preconfigured scripts to jump-start your mass changes, which is possible with PowerGUI

http://powergui.org/index.jspa

and

VMware Community Pack

http://www.virtu-al.net/featured-scripts/vmware-powerpack/

It's also worth looking at The free VMware Guest Console

http://labs.vmware.com/flings/vgc

The free VMware Guest Console, an experimental application created by VMware Labs, is a great tool for managing vSphere VM processes and files. You can view, sort and kill processes across all VMs, and you can also run a script on all Windows or Linux VMs.

If you do want a script, LucD. His website is here http://www.lucd.info/. He has written many books on the PowerCLI scripts.

 
Foreach ($VMHost in Get-VMHost){
	Foreach ($vSwitch in ($VMHost | Get-VirtualSwitch )){
		$NicTeaming = Get-NicTeamingPolicy -VirtualSwitch $vSwitch
		$obj = new-object psobject
		$obj | Add-Member -membertype NoteProperty -Name Host -value $VMHost
		$obj | Add-Member -membertype NoteProperty -Name vSwitch -value $vSwitch
		$obj | Add-Member -membertype NoteProperty -Name NumPorts -value $vSwitch.NumPorts
		$obj | Add-Member -membertype NoteProperty -Name NumPortsAvailable -value $vSwitch.NumPortsAvailable
		$PG = $vSwitch | Get-VirtualPortGroup
		If ($PG.Count -gt 1){
			$obj | Add-Member -membertype NoteProperty -Name PortGroups -value ([string]::join(' , ',($PG)))
		}
		Else {
			$obj | Add-Member -membertype NoteProperty -Name PortGroups -value $PG
		}
		$obj | Add-Member -membertype NoteProperty -Name BeaconInterval -value $NicTeaming.BeaconInterval
		$obj | Add-Member -membertype NoteProperty -Name LoadBalancingPolicy -value $NicTeaming.LoadBalancingPolicy
		$obj | Add-Member -membertype NoteProperty -Name NetworkFailoverDetectionPolicy -value $NicTeaming.NetworkFailoverDetectionPolicy
		$obj | Add-Member -membertype NoteProperty -Name NotifySwitches  -value $NicTeaming.NotifySwitches 
		$obj | Add-Member -membertype NoteProperty -Name FailbackEnabled -value $NicTeaming.FailbackEnabled
		If ($NicTeaming.ActiveNic -gt 1){
			$obj | Add-Member -membertype NoteProperty -Name ActiveNic -value ([string]::join(' , ',($NicTeaming.ActiveNic)))
		}
		Else {
			$obj | Add-Member -membertype NoteProperty -Name ActiveNic -value $NicTeaming.ActiveNic
		}
		If ($NicTeaming.StandbyNic -gt 1){
			$obj | Add-Member -membertype NoteProperty -Name StandbyNic -value ([string]::join(' , ',($NicTeaming.StandbyNic)))
		}
		Else {
			$obj | Add-Member -membertype NoteProperty -Name StandbyNic -value $NicTeaming.StandbyNic
		}
		If ($NicTeaming.UnusedNic -gt 1){
			$obj | Add-Member -membertype NoteProperty -Name UnusedNic -value ([string]::join(' , ',($NicTeaming.UnusedNic)))
		}
		Else {
			$obj | Add-Member -membertype NoteProperty -Name UnusedNic -value $NicTeaming.UnusedNic
		}
		$obj | Add-Member -membertype NoteProperty -Name CheckBeacon  -value $NicTeaming.CheckBeacon
		$obj.PSTypeNames.Clear()
		$obj.PSTypeNames.Add('Virtu-al.PowerPack.vSwitchInfo')
		$obj.PSTypeNames.Add('Virtu-al.PowerPack.NET')
		$obj
	}
}

Open in new window


the above code lists vSwitch detail information Portgroup is the variable which would need setting.

Andrew Hancock (VMware vExpert / EE Fellow)VMware and Virtualization Consultant
Fellow 2018
Expert of the Year 2017

Commented:
Using PowerCLI, PowerGUI and the VMware Community Pack you can change the Network the Virtual Machine is connected to, just needed to browse around.

You select the Virtual Machine, Links, Network Adaptors, Change Properties.

 Change Network Name using PowerCLI
Andrew Hancock (VMware vExpert / EE Fellow)VMware and Virtualization Consultant
Fellow 2018
Expert of the Year 2017

Commented:
So if you install the above, and connect to vSphere vCenter, you will be able to complete this with no development time.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial