Leffingwell
Contributor
Contributor

vNIC mapping - issues

Hello,

All, I have been at this for hours and while I can pull each of these values indirectly, I have been unsuccessful in putting them together into a single spreadsheet.  The biggest issue is not being able to find a correlation from a given VM's vNIC, that vNIC's port-group, and what specific vSwitch(or VDS) that vNIC/port-group are attached to.

Ideally I would have columns like:

VMname | vNIC | MAC | MAC type | vSwitch | PortGroup

Where multiple vNIC's would mean multiple rows with the same VMname.

I feel like if I can pull all of the above data directly from a VM object I can make this work, however, after looking through view data and extension data I couldn't find this information.  Any and all insight here will be greatly appreciated!!

I can definitely provide some of my attempts if people need a frame of reference, however, as they're just bits and pieces I didn't want to pidgeon hole the discussion out the gate with my ill-conceived attempts. 

Thank you in advance for any insight you may have!

0 Kudos
4 Replies
LucD
Leadership
Leadership

What do you mean by Mac Type, is that Automatic or Manual?

I assume that the VMware Tools are installed and running on the VM?


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

0 Kudos
Leffingwell
Contributor
Contributor

Hello,

Yes sir, Auto / Manual and Tools may or may not be on every VM. 

It's been a long time since I've posted here, but it's good to hear from you again!

0 Kudos
Leffingwell
Contributor
Contributor

Hello,

Luc, I was able to finally get a console output highlighting the relationship I want (sans the easy bits like MAC / MAC type), now I just need some guidance on how to take this output and format each cascade in the output into a spreadsheet like I described in the first post.  Thank you again for any possible insight here!

$clusters = Get-Cluster

foreach ($cluster in $clusters){

    "Cluster $cluster"

    $vmhosts = $cluster | Get-VMHost

        foreach ($vmhost in $vmhosts){

        "`tHost $vmhost"

        $vdswitches = $vmhost | Get-vdswitch

            foreach ($switch in $vdswitches){

                "`t`tvdSwitch $switch"

                $dvports = $switch | Get-VDPortgroup

                    foreach ($dvport in $dvports){

                        "`t`t`tPort group $dvport"

                        $vms = $dvport | Get-VM

                            foreach ($vm in $vms){

                            $vnics = $vm.NetworkAdapters

                                foreach ($vnic in $vnics){

                                    if($_.Name -eq  $dvport){

                                    $vnic = $_.Name

                                    }

                                }

                            "`t`t`t`t"+$vm.Name+" - $vnic"

                            }

                    }

            }

    }

0 Kudos
LucD
Leadership
Leadership

Try something like this

$clusters = Get-Cluster

$report = foreach ($cluster in $clusters){

    "Cluster $cluster"

    $vmhosts = $cluster | Get-VMHost

        foreach ($vmhost in $vmhosts){

        $vdswitches = $vmhost | Get-vdswitch

            foreach ($switch in $vdswitches){

                $dvports = $switch | Get-VDPortgroup

                    foreach ($dvport in $dvports){

                        $vms = $dvport | Get-VM

                            foreach ($vm in $vms){

                            $vm.NetworkAdapters | where{$_.NetworkName -eq  $dvport} |

                            Select @{N='Cluster';E={$cluster.Name}}

                                @{N='VMHost';E={$vmhost.Name}},

                                @{N='Switch';E={$switch.Name}},

                                @{N='PortGroup';E={$dvPort.Name}},

                                @{N='vNIC';E={$_.Name}}

                            }

                    }

            }

    }

}

$report | Export-Csv report.csv -NoTypeInformation -UseCulture


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

0 Kudos