Check vm vmnic vlan

by Grzegorz Kulikowski

I wanted to get a list of vms that are using specific vlan so i wrote this one:
[sourcecode language=”powershell”]
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 :
[sourcecode language=”powershell”]
$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.

You may also like

1 comment

suresh May 18, 2018 - 6:25 am

Hello – I tried running your script to get the vla info but getting an error saying get-view is not recognized as the name of cmdlet.


Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish
Streaming live on Twitch right now.