VMware Cloud Community
btok
Contributor
Contributor
Jump to solution

MACAdress issue

I'm trying to add the display of macaddress to a postes script. What am I missing with the mac to actually get it to list with the VMname & the IPaddress

get-vm | % {

$vm = Get-View $_.ID

$vms = "" | Select-Object VMName, IPAddress, MACAddress

$vms.VMName = $vm.Name

$vms.IPAddress = $vm.guest.ipAddress

$vms.MACAddress = $vm.nic.MACAddress

Thanks for your help

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Or you can do it this way.

It will show all NICs present on a guest.

$report = @()
Get-VM | %{
  foreach($nic in $_.Guest.Nics) {
    $row = "" | select VMName, IP, MAC
    $row.VMName = $_.name
    $row.IP = $nic.macAddress
    $row.MAC = $nic.IPAddress
    $report += $row
  }
}
$report


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

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

For the MAC address have a look at


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

Reply
0 Kudos
btok
Contributor
Contributor
Jump to solution

Luc,

How can you tie the two of these together?

Thanks for your help

$Report = @()

get-vm | % {

$vm = Get-View $_.ID

$vms = "" | Select-Object VMName, IPAddress

$vms.VMName = $vm.Name

$vms.IPAddress = $vm.guest.ipAddress

$Report += $vms

}

$Report

Get-VM | select name, @{Name="MAC"; expression={foreach($nic in (Get-View $_.ID).guest.net) {$nic.macAddress}}}

Reply
0 Kudos
olan025
Enthusiast
Enthusiast
Jump to solution

you could just wrap it all in a foreach like this, set the values, then echo them in line.

one way to do it..... you can add a | out-file -append "text.txt" file after teh echo line to write a file.

if so, then have a out-file w/o append at the beginning to clear anything left from before.

LucD
Leadership
Leadership
Jump to solution

Or you can do it this way.

It will show all NICs present on a guest.

$report = @()
Get-VM | %{
  foreach($nic in $_.Guest.Nics) {
    $row = "" | select VMName, IP, MAC
    $row.VMName = $_.name
    $row.IP = $nic.macAddress
    $row.MAC = $nic.IPAddress
    $report += $row
  }
}
$report


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

Reply
0 Kudos
btok
Contributor
Contributor
Jump to solution

Luc

This is exactly what I was after

thanks for your help

B

Reply
0 Kudos