Hi folks,
I have a distributed port group in VMware that I want to query for connected VMs.
The code below returns VMs; but the names are not what I was expecting.
$portgroups = Get-VDPortgroup -Name vLAN-1234
foreach ($pg in $portgroups) {
$pg.ExtensionData.vm
}
Type Value
Type Value
---- -----
VirtualMachine vm-4679
VirtualMachine vm-2414
VirtualMachine vm-8691
How do track this "VM name" back to a VM?
Thanks in advance. ![]()
Updated PowerShell code.
$portgroups = Get-VDPortgroup -Name vLAN-1234
$connectedvms = @()
foreach ($pg in $portgroups) {
$vms = $pg.ExtensionData.vm
foreach ($vm in $vms) {
$vmid = "virtualmachine-" + $vm.value
$connectedvm = $null
$connectedvm = (Get-View -Id $vmid).name
$connectedvms += $connectedvm
}
}
$connectedvms | sort
Came up with the answer after posting!
Might be of use to someone somewhere.
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Updated PowerShell code.
$portgroups = Get-VDPortgroup -Name vLAN-1234
$connectedvms = @()
foreach ($pg in $portgroups) {
$vms = $pg.ExtensionData.vm
foreach ($vm in $vms) {
$vmid = "virtualmachine-" + $vm.value
$connectedvm = $null
$connectedvm = (Get-View -Id $vmid).name
$connectedvms += $connectedvm
}
}
$connectedvms | sort
Came up with the answer after posting!
Might be of use to someone somewhere.
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
