VMware Cloud Community
Anton_Louw
Contributor
Contributor
Jump to solution

Change a list of MAC Addresses from an old Port Group to a new Port Group

Hi All,

I have a list of around 90 MAC addresses that need to be changed to a different Port Group. I would do this through the Web Client, but it's going to take forever. Is there a way I can change the Port Groups on all the VM Adapters MAC addresses that match my list?

Any examples would be greatly appreciated.

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$newPG = 'NewPortgroup'

$macList = Import-Csv -Path .\maclist.csv -UseCulture | Select -ExpandProperty MACAddress


Get-VM | Get-NetworkAdapter |

where{$macList -contains $_.MacAddress} |

Set-NetworkAdapter -Portgroup $newPG -Confirm:$false


This assumes that you have the target MAC addresses in a CSV file (maclist.csv in the example code above) that has the below layout.
Where <mac1>, <mac2> ... are your target MAC addresses.
Note that the MAC address returned by Get-NetworkAdapter has the format '00:50:56:xx:xx:xx' .

Your CSV file will need to use the same formatting

MACAddress

<mac1>

<mac2>


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Just to make sure I understand the question.

You have a list of MAC addresses?
These MAC addresses are used on a number of VMs?All the vNICs that have one of these MAC addresses need to be set to another Portgroup?
Are these MAC addresses generated by vSphere or are they manual MAC addresses?

Changing a vNIC to another Portgroup can be done through the Get-NetworkAdapter and Set-NetworkAdapter cmdlets.


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

Reply
0 Kudos
Anton_Louw
Contributor
Contributor
Jump to solution

Thanks for the reply LucD

Yes, so any Network Adapter in my environment that has a MAC address that is in my list, needs to change to a different port group. The MAC addresses are all generated by VMware. I can try the below script, but I will still need to run it numerous times to change each network adapter to a different port group:

Get-VM | Get-NetworkAdapter | Where-Object {$_.MacAddress -eq $vmMAC } | Set-NetworkAdapter -NetworkName $virtualportgroup

Is there a way to refer the above script to read content from my text file and then do the changes?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$newPG = 'NewPortgroup'

$macList = Import-Csv -Path .\maclist.csv -UseCulture | Select -ExpandProperty MACAddress


Get-VM | Get-NetworkAdapter |

where{$macList -contains $_.MacAddress} |

Set-NetworkAdapter -Portgroup $newPG -Confirm:$false


This assumes that you have the target MAC addresses in a CSV file (maclist.csv in the example code above) that has the below layout.
Where <mac1>, <mac2> ... are your target MAC addresses.
Note that the MAC address returned by Get-NetworkAdapter has the format '00:50:56:xx:xx:xx' .

Your CSV file will need to use the same formatting

MACAddress

<mac1>

<mac2>


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

Reply
0 Kudos
Anton_Louw
Contributor
Contributor
Jump to solution

What a guy! Just ran this on some test VMs and it worked like a charm!

Thanks for the assistance LucDSmiley Happy

Reply
0 Kudos