Monday, November 23, 2015

PowerCLI script to query a VLAN for specific VM members.


Here's a script that will show you all the VMs that belong to a specific VLAN within vCenter. This is handy when you have multiple VLANs created and don't know which VMs belong to which VLAN.

#Production_VLAN is the name of the VLAN you are querying
$vms=get-view -viewtype virtualmachine
foreach($vmview in $vms )
{
$ntwkview=get-view -id $vmview.network
foreach($ntwkentry in $ntwkview){
if ($ntwkentry.name -eq "Production_VLAN")
{
$vmview.name
}
}
}

No comments:

Post a Comment