cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

PowerCli 6.5 script to change the distributed port groups for a list of vm's in a csv file - useful for ACI migrations

110
Views
0
Helpful
0
Comments

Create a CSV with the following for column headings..

  • vmname,nwadapter,nwname,acipg
vmname,nwadapter,nwname,acipg
vm1, Network Adapter 1, currentpg100, newportgroup100
vm2, Network Adapter 1, currentpg200, newportgroup200
vm2, Network Adapter 2, currentpg300, newportgroup300

The information in the csv should be gathered from vceter as follows...

  • vmname = name of vm in vcenter
  • nwadapter = "Network adapter #" depending on which vnic of the vm
  • nwname = name of the currently connected port group (can be standard or distributed)
  • acipg = name of new port group (distributed only - esxi host must be added to the dvs first)
#Credentials
$vcenterIP = '10.10.10.10'
$vcusername = 'admin@vc.local'
$vcpass = 'Cisco123'

#Connect to vCenter and gather info
Connect-VIServer -Server $vcenterIP -Protocol https -User $vcusername -Password $vcpass

#Set Variables to point to the csv with your import data
$csvpath = '.\vmnics.csv'

#change the network (portgroup) for each network adapter in each vm in the csv
$vmniclist = import-csv $csvpath
ForEach ($vmpg in $vmniclist){
$vmname = $($vmpg.vmname)
$nwadapter = $($vmpg.nwadapter)
$nwname = $($vmpg.nwname)
$acipg = $($vmpg.acipg)
Write-Host -NoNewline $vmname "is being migrated to the Cisco ACI network." $nwadapter "is moving its connection from" $nwname "to" $acipg 
$myvmpg = Get-VM -Name $vmname | Get-NetworkAdapter -Name $nwadapter | Get-VDPortGroup
$mynewpg = Get-VirtualPortGroup -Name $acipg
Get-VM -Name $vmname | Get-NetworkAdapter -Name $nwadapter | Set-NetworkAdapter -PortGroup $mynewpg -confirm:$False
}

Disconnect-VIServer -Server $vcenterIP -Force

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards
This widget could not be displayed.