Reply to Message

View discussion in a popup

Replying to:
rwk1982
Enthusiast
Enthusiast

Hello!

This one is years old and not the fastest but i was always to lazy to optimize it :slightly_smiling_face:

$vms = Get-Content c:\temp\vms.txt

Get-VM $vms | foreach {

	$vm = $_
	$vm_name = $vm.Name

	$vm | Get-NetworkAdapter | foreach {

		$vm_nic = $_
		$vm_nic_name = $vm_nic.Name
		$vm_nic_net_name = $vm_nic.NetworkName
		$vm_nic_mac = $vm_nic.MacAddress

		$vm_nic_vlanid = (Get-VDPortgroup -NetworkAdapter $vm_nic).VlanConfiguration.VlanId

		if (!$vm_nic_vlanid) {

			$vm_nic_vlanid = ($vm | Get-VirtualPortGroup -Name $vm_nic_net_name)[0].VLanId

		}


		$vm_name + "|" + $vm_nic_name + "|" + $vm_nic_net_name + "|" + $vm_nic_vlanid + "|" + $vm_nic_mac

	}

}
Drink coffee.. Do stupid things faster with more energy...