Hi
I'm trying to get the vm IP and MAC from one of my datacenters.
When I run the following script two things happen:
1. I only see one vm in the csv file output.
2. When I send the output to the PowrCLI prompt I only see one mac and one IP for vm's that have to nics.
Script
---------
$VMs = Get-Datacenter $DC | 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}} |
Export-CSV VM-IP-Info.csv -NoTypeInfo
}
}
}