VMware Cloud Community
BowDaddy
Contributor
Contributor

Creating an additional network adapter for existing VM

I'm looking for a script to add an additional network adapter to multiple VMs from a CSV.

I know how to import the CSV, just need the syntax to create the Network adapter port group titled Isolation.

The start of my script is:

if ((Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null) {

    Add-PSsnapin VMware.VimAutomation.Core

    }

$vcenter = Read-Host "Enter VI Server IP"

Connect-VIServer $vcenter

$VMs = import-csv C:\scripts\vms_PRODTEST.csv

foreach ($vmList in $VMs) {

    $vm = Get-VM $vmList.vm

    $vm | Get-NetworkAdapter.....

Thank you.

0 Kudos
1 Reply
LucD
Leadership
Leadership

Try like this

Import-Csv C:\scripts\vms_PRODTEST.csv | %{

    New-NetworkAdapter -VM $_.Name -Type Vmxnet3 -NetworkName $_.Portgroup -StartConnected:$false -Confirm:$false

}

This assumes the CSV has the following layout

Name,Portgroup

VM1,PG1

VM2,PG3


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

0 Kudos