I want to get a list of VMs with a given vlan name configured so that when I am rolling back a vlan, with ACI I am certain that it is gone.
This script works, I connect to the vcenter with powercli and pass in a vlan_name:
foreach ($vm in Get-VM){
$nic = Get-NetworkAdapter -VM $vm.name
if ( $nic.NetworkName -eq "{{ vlan_name }}" ){
echo $vm.name
}
}
The problem is, it is an O(n) sort of algorithm and takes a long time to run (I have thousands of VMs and hundreds of vlans)
The annoying thing is
Get-VM | Get-NetworkAdapter
lists all the vlan's quickly, but doesn't output the vm names.
Is there a way I can get the VM use by Network Adapter?
This PowerShell lists out the VM name, the network adapter, and the type of network it's connected.
PowerShell
or
Sample Output
PowerShell (Filter Network Name)
Supporting Resources
Select-Object
Where-Object
Calculated_Properties
Add a calculated property with Select-Object in PowerShell