I wrote this to help a client migrate to VXLAN from portgroups.
It pulls from a CSV file named c:\scripts\ImportPortGroups.csv which is structured:
VLAN,PortGroup,wire
123,dVLAN 123,192.168.123.0/24
and accepts the initial number (VLAN) as a commandline parameter such as:
changeportgroups 123
The CSV file needs: identifier, portgroup name, virtual switch name
If you don’t enter a initial parameter it will remind you and exit.
Entering an initial parameter, the script grabs the line from the CSV where the first value matches your input.
It will then:
Pull the PG and VS from vcenter and verify that is what you are looking to work with.
Pull the number of VMs on the PG and VS and display and ask which way the move should go (all to VS or all to PG)
Migrate the VMs and display the # of VMs on the PG and VS.
You can get the script here.
FYI the one-liner version of the script is:
get-vm | get-networkadapter |where {$_.networkname -eq “OldPortGroup”} | set-networkadapter -networkname “NewPortGroup” -Confirm:$false