VMware Cloud Community
PorzioM
Contributor
Contributor
Jump to solution

How to get VM name in output along with each of its adapters mac address

I am trying to come up with a way to get a list of all VMs in an environemnt with their adapters mac address. I'm trying to hunt down a possible duplicate mac address in a large virtual environment

what I have so far:

Get-VM | Get-View | Select-Object -Property Name, @{N=”MAC”;E={$_.MacAddress}} | Export-Csv C:\filename.csv -NoTypeInformation

This will get me the adapter name and the mac address but not the VM name. Can someone help me with the rest? thanks.

0 Kudos
1 Solution

Accepted Solutions
display1284
Contributor
Contributor
Jump to solution

I don’t know what you consider large? We are hosting around 5k+ virtual servers and a few farms. If running on production system could take some major time

Search it all - Full dump
save as FullDumpMac.ps1

# FULL DUMP VM/Mac


$fullDump = Get-VM | ForEach-Object {
$VM = $_
if ($VM) {
$VM.Guest.Nics | Select-Object -Property @{N=”VM”;E={$VM.Name}},Macaddress
}
}
$fullDump | Export-Csv report.csv -NoTypeInformation -UseCulture

Folder search

#Notice I am using a folder search from adjust to script to not have folder
$Dump = Get-Folder -Name demo | Get-VM | ForEach-Object {
$VM = $_
if ($VM) {
$VM.Guest.Nics | Select-Object -Property @{N=”VM”;E={$VM.Name}},Macaddress
  }
}
$Dump | Export-Csv report.csv -NoTypeInformation -UseCulture

 

Best of Luck,

(A}{E -  Kansas City)

[Wisdom comes from experience, and experience comes from bad decisions. ]

View solution in original post

0 Kudos
2 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

Take a look at my blog post How to use VMware vSphere PowerCLI to find the MAC addresses of a virtual machine.

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
display1284
Contributor
Contributor
Jump to solution

I don’t know what you consider large? We are hosting around 5k+ virtual servers and a few farms. If running on production system could take some major time

Search it all - Full dump
save as FullDumpMac.ps1

# FULL DUMP VM/Mac


$fullDump = Get-VM | ForEach-Object {
$VM = $_
if ($VM) {
$VM.Guest.Nics | Select-Object -Property @{N=”VM”;E={$VM.Name}},Macaddress
}
}
$fullDump | Export-Csv report.csv -NoTypeInformation -UseCulture

Folder search

#Notice I am using a folder search from adjust to script to not have folder
$Dump = Get-Folder -Name demo | Get-VM | ForEach-Object {
$VM = $_
if ($VM) {
$VM.Guest.Nics | Select-Object -Property @{N=”VM”;E={$VM.Name}},Macaddress
  }
}
$Dump | Export-Csv report.csv -NoTypeInformation -UseCulture

 

Best of Luck,

(A}{E -  Kansas City)

[Wisdom comes from experience, and experience comes from bad decisions. ]

0 Kudos