For VM's that have multiple adapters I would like all the network names and mac addresses to go in the same two columns on the same row... rather than having to do MAC1 MAC2, MAC3 ... so on and so forth
$array = @()
foreach ($item in $csv) {
$info = "" | Select VMName, DNSName, IP, PortGroup, MAC, vCenter
$vm = Get-VM $item.name
$adapters = $vm | Get-NetworkAdapter
$info.VMName = $vm.name
$info.DNSName = $vm.guest.hostname
$info.IP = $vm.guest.ipaddress[0]
foreach ($adapter in $adapters) {
$info.PortGroup = $adapter.NetworkName
$info.MAC = $adapter.MacAddress
}
$info.vCenter = $vm.vCenterServer
$array += $info
}
Try it like this
$array = @() foreach ($item in $csv) { $info = "" | Select VMName, DNSName, IP, PortGroup, MAC, vCenter
$vm = Get-VM $item.name
$adapters = $vm | Get-NetworkAdapter
$info.VMName = $vm.name
$info.DNSName = $vm.guest.hostname
$info.IP = $vm.guest.ipaddress[0] $info.PortGroup = [string]::Join(',',($adapters | Select -ExpandProperty NetworkName)) $info.MAC = [string]::Join(',',($adapters | Select -ExpandProperty MacAddress)) $info.vCenter = $vm.vCenterServer
$array += $info
}
With the Join function you paste together multiple values into 1 string
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try it like this
$array = @() foreach ($item in $csv) { $info = "" | Select VMName, DNSName, IP, PortGroup, MAC, vCenter
$vm = Get-VM $item.name
$adapters = $vm | Get-NetworkAdapter
$info.VMName = $vm.name
$info.DNSName = $vm.guest.hostname
$info.IP = $vm.guest.ipaddress[0] $info.PortGroup = [string]::Join(',',($adapters | Select -ExpandProperty NetworkName)) $info.MAC = [string]::Join(',',($adapters | Select -ExpandProperty MacAddress)) $info.vCenter = $vm.vCenterServer
$array += $info
}
With the Join function you paste together multiple values into 1 string
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the prompt response, let me give it a try.
Throws a parsing error... think you have an extra "(" after the join function.
Correct, just updated the code
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference