Pages: [1]
Print
Author Topic: List virtual machine with its ipaddresses and mac addresses  (Read 1847 times)
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« on: March 11, 2009, 09:33:44 AM »

Code:
$VMs = get-vmhost | Get-VM
foreach ($VM in $VMs){
    $VMx = Get-View $VM.ID
$HW = $VMx.guest.net
foreach ($dev in $HW)
    {
        foreach ($ip in $dev.ipaddress)
        {
            $dev | select @{Name = "Name"; Expression = {$vm.name}},@{Name = "IP"; Expression = {$ip}}, @{Name = "MAC"; Expression = {$dev.macaddress}}
        }
    }
}
Logged
aflora
Newbie
*
Posts: 16


View Profile
« Reply #1 on: June 16, 2009, 08:04:29 PM »

Hi

When I try to pipe this script to a csv file I get the folowing error:
"Cannot bind argument to parameter 'InputObject' because it is null"
The script returns this error but creates the csv file with the data none the less?
Must be a data format quirk when exporting to a csv file. Works with no errors when I use html format.

$report =@()
$VMs = get-vmhost | Get-VM
foreach ($VM in $VMs){
    $VMx = Get-View $VM.ID
   $HW = $VMx.guest.net
   foreach ($dev in $HW)
    {
        foreach ($ip in $dev.ipaddress)
        {
       $report +=  $dev | select @{Name = "Name"; Expression = {$vm.name}},@{Name = "IP"; Expression = {$ip}}, @{Name = "MAC"; Expression = {$dev.macaddress}}
        }
    }
}
$report | export-csv -NoType d:\VmReport.csv

Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #2 on: June 17, 2009, 07:53:03 AM »

wonder if its a bug, because i'm getting the same results  you are, regardless of what i try Smiley
Logged
alanrenouf
Newbie
*
Posts: 1


View Profile Email
« Reply #3 on: June 17, 2009, 08:38:44 AM »

Try this:

Code:
$Report = @()
$VMs = get-vmhost | Get-VM
foreach ($VM in $VMs){
   $VMx = Get-View $VM.ID
   $HW = $VMx.guest.net
   foreach ($dev in $HW)
    {
        foreach ($ip in $dev.ipaddress)
        {
      $MyDetails = "" | select-Object Name, IP, MAC
$MyDetails.Name = $vm.name
$MyDetails.IP = $ip
$MyDetails.MAC = $dev.macaddress
$Report += $MyDetails
        }
    }
}
$report | export-csv -NoType C:\VmReport.csv
« Last Edit: June 17, 2009, 08:59:31 AM by esarakaitis » Logged
aflora
Newbie
*
Posts: 16


View Profile
« Reply #4 on: June 17, 2009, 03:44:43 PM »

Thanks...this works with no errors. Thanks for your help. Your site and scripts are very useful.
Logged
Pages: [1]
Print
Jump to: