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
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
For the MAC address have a look at
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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}}}
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.
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
Luc
This is exactly what I was after
thanks for your help
B