VMware Cloud Community
Chrigoli
Enthusiast
Enthusiast

Add new NIC to VM (like New-CINetworkAdapter)

Hi all

I'm trying to find out how to simply add a new NIC to a VM within a vApp.

Something like "New-CINetworkAdapter" would be great, but unfortunately does not exist..

Anyone some experience or tipps for me on how to add a NIC to a VM within vCloud Director?

Have already tried to create the NIC via New-NetworkAdapter in vSphere (which actually works), but then vCloud Director does not recognize the NIC and still thinks the VM has no NIC.

Thanks and cheers

Chrigoli

Reply
0 Kudos
4 Replies
johndavidd
Enthusiast
Enthusiast

Did you ever figure anything out here? It's amazing you can't add a NIC through the command line.

Reply
0 Kudos
Chrigoli
Enthusiast
Enthusiast

Unfortunately not 😞 and had no time to investigate this thing further..

Reply
0 Kudos
znuz
Contributor
Contributor

I'm also looking for this ability. Seems crazy that there isn't a way to add a second NIC through powershell.

Reply
0 Kudos
jdegier
Contributor
Contributor

Try this one, I finally got it working.

I'm using Powershell 4.0 en PowerCLI for Tenants 5.8.

Change MYVCLOUD, MYORG, MYUSER, MYPWD and MYVM for your environment.

Header 1

# Add vcloud cmdlets

if( -not (Get-PSSnapin VMware.VimAutomation.Common) )

{

    Add-PSSnapin VMware.VimAutomation.Common

}

if( -not (Get-PSSnapin VMware.VimAutomation.Cloud) )

{

    Add-PSSnapin VMware.VimAutomation.Cloud

}

# connect to vcloud

if( $global:DefaultCIServers[0].IsConnected -eq $false )

{

    Connect-CIServer -server MYVCLOUD -Org MYORG -User MYUSER -Password 'MYPWD'

}

$targetvm = "MYVM"

$vm = get-civm | where{ $_.name -eq $targetvm }

$headers = @{"Accept"="application/*+xml;version=5.5"}

$headers += @{"x-vCloud-authorization"="$($global:DefaultCIServers[0].SessionId)"}

$url = "$($vm.ExtensionData.GetVirtualHardwareSection().href)networkCards"

$response = Invoke-RestMethod -Uri $url -Headers $headers -Method GET -WebSession $MYSESSION

[xml]$nics = $response

$topInstanceID = [int](@($nics.RasdItemsList.Item | Sort-Object instanceID))[-1].instanceID

$topAddressOnParent = [int](@($nics.RasdItemsList.Item | Sort-Object AddressOnParent))[-1].AddressOnParent

$topElementName = [int]((@($nics.RasdItemsList.Item | Sort-Object ElementName))[-1].ElementName).Split()[-1]

$newNic = @($nics.RasdItemsList.Item)[-1].CloneNode(1)

$newNic.InstanceID = "$([int]$topInstanceID+1)"

$newNic.AddressOnParent = "$([int]$topAddressOnParent+1)"

$newNic.Address = ""

$newNic.ResourceSubType = "VMXNET3"

$newNic.ElementName = "Network adapter $([int]$topElementName+1)"

$newNic.Connection.primaryNetworkConnection = "false"

$nics.RasdItemsList.AppendChild( $newNic )

Invoke-RestMethod -Uri $url -Headers $headers -Method PUT -WebSession $MYSESSION -Body $nics

Reply
0 Kudos