Enumerate network adapters Powershell (PowerCLI) – VMware vmnic

This is a script I wrote a while ago to enumerate network adapters Powershell (PowerCLI) and add the total amount to a variable. I thought some people may find it useful.

enumerate network adapters Powershell

What I am achieving here is actually enumerating (count) the number of vmnic’s in a host. Why? Well if you think about automating your ESXi deployment, not all physical hosts have the same configurations, some have 4 1GB Nic’s others have 2 10GB nics, however you want to have a standard build for all configurations. This is an easy way to be able to automatically create the portgroups required without having to change your builds for different configurations.

The script below shows how you can easily count the total number of vmnics and add to the variable no_nics.

[powershell]

$no_nics = get-vmhostnetworkadapter -Physical

##Sets Physical NIC count to -1 to match VMware NIC names, eg, vmnic0, vmnic1 etc.
$vmnic_no = $no_nics.count -1

write-host "Number of physical adapters" $no_nics.count

[/powershell]

In a follow up post, I will be showing how to take this total vmnic count and create virtual machine port groups using an array.

enumerate network adapters Powershell

No comments yet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright David Hill

Powered by WordPress. Designed by Woo Themes

Close Bitnami banner
Bitnami