Check vm vmnic vlan

I wanted to get a list of vms that are using specific vlan so i wrote this one:

foreach($vm in (get-vm)){
if (Get-NetworkAdapter -vm $ |?{$_.NetworkName -eq "network23" -or $_.NetworkName -eq "network65"}){$}

Ok, that was working but it was VERY VERY VERY VERY VERY slow…

So i wrote it using get-view :

$vms=get-view -viewtype virtualmachine
foreach($vmview in $vms )
$ntwkview=get-view -id $
foreach($ntwkentry in $ntwkview){
if ($ -eq "network23" -or $ -eq "network65")

This one needed only 3 minutes to complete on a ~1000vm infrastructure. I stop the first script after 30minutes of running as it would probably finish next day …

The script is not perfect… yet 😉 but it will do the job and what’s most important quickly. I hope this will save you some time on reporting.