VMware Cloud Community
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Need VM's VLAN inventory for each network adapter

Hi,

I'm looking for VM's VLAN inventory for each network adapter, the script will list out the following details in CSV file output.

VMname  |  Cluster Name |  NIC Name-1  |  VLAN Name  | NIC Name-2  |  VLAN Name  |


Thanks in advance!

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
0 Kudos
1 Solution

Accepted Solutions
Grzesiekk
Expert
Expert
Jump to solution

Hi there,

$(gkulikowski#08:15:06> get-vm | %{ $clustername=($_ | get-cluster).name; $_|Get-NetworkAdapter | select @{N='VM name';E={$_.Parent}},@{N='Cluster';E={$clustername}},NetworkName,@{N='NetworkCard';E={$_.Name}} } ) | export-csv -Path c:\out.csv

but this will output this as

VM name                 Cluster                                      NetworkName                                  NetworkCard
-------                         -------                                      -----------                                  -----------

So if you have more than 2 vnics you will see them as well. not as columns but as rows.

Ok, and if you want to have it in columns, i wrote it like this:

$( get-vm testgk | %{ $clustername=($_ | get-cluster).name; $ntwkcards=$_|Get-NetworkAdapter;"" | select @{N='VM name';E={$ntwkcards[0].Parent} },@{N='Cluster';E={$clustername}},@{N='NetworkCard 0';E={$ntwkcards[0].Name}},@{N='NetworkCard 0 vlan';E={$ntwkcards[0].NetworkName}},@{N='NetworkCard 1';E={$ntwkcards[1].Name}},@{N='NetworkCard 1 vlan';E={$ntwkcards[1].NetworkName}} }) | Export-Csv c:\out-file.csv

This will be the exact output as you asked for.

"VM name","Cluster","NetworkCard 0","NetworkCard 0 vlan","NetworkCard 1","NetworkCard 1 vlan"

You have mentioned vlan name, so i assumed you are thinking of portgroup name.

Greg

--- @blog https://grzegorzkulikowski.info

View solution in original post

0 Kudos
2 Replies
Grzesiekk
Expert
Expert
Jump to solution

Hi there,

$(gkulikowski#08:15:06> get-vm | %{ $clustername=($_ | get-cluster).name; $_|Get-NetworkAdapter | select @{N='VM name';E={$_.Parent}},@{N='Cluster';E={$clustername}},NetworkName,@{N='NetworkCard';E={$_.Name}} } ) | export-csv -Path c:\out.csv

but this will output this as

VM name                 Cluster                                      NetworkName                                  NetworkCard
-------                         -------                                      -----------                                  -----------

So if you have more than 2 vnics you will see them as well. not as columns but as rows.

Ok, and if you want to have it in columns, i wrote it like this:

$( get-vm testgk | %{ $clustername=($_ | get-cluster).name; $ntwkcards=$_|Get-NetworkAdapter;"" | select @{N='VM name';E={$ntwkcards[0].Parent} },@{N='Cluster';E={$clustername}},@{N='NetworkCard 0';E={$ntwkcards[0].Name}},@{N='NetworkCard 0 vlan';E={$ntwkcards[0].NetworkName}},@{N='NetworkCard 1';E={$ntwkcards[1].Name}},@{N='NetworkCard 1 vlan';E={$ntwkcards[1].NetworkName}} }) | Export-Csv c:\out-file.csv

This will be the exact output as you asked for.

"VM name","Cluster","NetworkCard 0","NetworkCard 0 vlan","NetworkCard 1","NetworkCard 1 vlan"

You have mentioned vlan name, so i assumed you are thinking of portgroup name.

Greg

--- @blog https://grzegorzkulikowski.info
0 Kudos
Srinivasu13
Enthusiast
Enthusiast
Jump to solution

Hi,

The output is not coming as expected and VM's details are missing. Can you look and revert me.

Thx

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, Srini
0 Kudos