VMware Cloud Community
jsenon
Contributor
Contributor
Jump to solution

Get Mac address for Guest-VM

Hi all,

I would like some help to provide a html document (with convert-html) that have three columns (VM Name, Type of @MAC (manual or assigned), @MAC).

I have search in the forum and I have found the command line to obtain all mac address for all VM : Get-VM | select name, @{Name="MAC"; expression={foreach($nic in (Get-View $_.ID).guest.net) {$nic.macAddress}}} but the parameters manual or assigned or not display.

Could you help me ?

Thank you for your help.

Regards.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The addressType property is not in that object.

With this script you should get the MAC address type

$report =@() 
Get-VM | Get-View | %{ 
 $VMname = $_.Name 
 $_.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "Network Adapter"} | %{` 
        $row = "" | Select VM, MAC, Type 
        $row.VM = $VMname 
        $row.MAC = $_.MacAddress 
        $row.Type = $_.AddressType 
        $report += $row 
  } 
  } 
$report 


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

The addressType property is not in that object.

With this script you should get the MAC address type

$report =@() 
Get-VM | Get-View | %{ 
 $VMname = $_.Name 
 $_.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "Network Adapter"} | %{` 
        $row = "" | Select VM, MAC, Type 
        $row.VM = $VMname 
        $row.MAC = $_.MacAddress 
        $row.Type = $_.AddressType 
        $report += $row 
  } 
  } 
$report 


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

0 Kudos
jsenon
Contributor
Contributor
Jump to solution

Thanks a lot. It's work Fine, just a 'after { must be delete.

Have a nice day.

0 Kudos
xooops
Contributor
Contributor
Jump to solution

Hi

great script thanks, !!!

is there a possibility to add a search mask for only specified vm's. Like run the script only in vm where the name contains production or so?

best regards, Sven

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, the Get-Vm cmdlet accepts masks

$report =@() 
Get-VM "*production*" | Get-View | %{ 
 $VMname = $_.Name 
 $_.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "Network Adapter"} | %{
        $row = "" | Select VM, MAC, Type 
        $row.VM = $VMname 
        $row.MAC = $_.MacAddress 
        $row.Type = $_.AddressType 
        $report += $row 
  } 
  } 
$report 


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

0 Kudos
xooops
Contributor
Contributor
Jump to solution

I try to run the script in PowerGUI. But no entry's are displayed. I think it's a problem with the rows.

best regars, sven

0 Kudos
xooops
Contributor
Contributor
Jump to solution

hey LucD

many many thanks,

0 Kudos