Skip to content

Instantly share code, notes, and snippets.

@standaloneSA
Created April 28, 2015 12:28
Show Gist options
  • Save standaloneSA/bc2dc758005bccda4c81 to your computer and use it in GitHub Desktop.
Save standaloneSA/bc2dc758005bccda4c81 to your computer and use it in GitHub Desktop.
Get the switchport a VM NIC is attached to
$MYHOSTNAME = "Your.Host.Here"
$VMNIC = "vmnic0"
$NS = (((Get-VMhost -name $MYHOSTNAME) | Get-View).ConfigManager.NetworkSystem)
(((Get-view -ID $NS).NetworkINfo.Pnic |
Where-Object { $_.Device -eq $VMNIC } |
%{ (Get-View -ID $NS).QueryNetworkHint($_.Device) }).ConnectedSwitchPort).PortID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment