Forum Discussion
ahinterl
Mar 25, 2025Copper Contributor
PowerShell, Hyper-V: Examine network object relationships.
Is it possible in PowerShell do do things like:
- Get all VMNetworkAdapters connected to a given VMSwitch
- Get all VMNetworkAdapters provided by a hypervisor (conected to either a VM or the management OS)
- When I have the name of a VMNetworkAdapter only, determine whether it's connected to the management OS, or a VM, and if connected to a VM, what VM that is
without examining each single endpoint (VM, management OS) and creating a database of objects and their relationships that allows me to get the desired information? Certainly not a couple of PowerShell code lines only, and depending on the size and type (remote, local) of the virtualization environment, I can imagine that time is a factor too.
2 Replies
Sort By
- LainRobertsonSilver Contributor
Hi ahinterl,
The short answer is yes, however, there's quite a few approaches to doing so - more than I'm prepared to cover in detail.
Here's some sample one-liner commands that pull some of what you're after through talking to the hypervisor - not each virtual guest. These demonstrate basic functionality, where in practice you'd likely want to pair these with other commands like Invoke-Command to fetch data in parallel, allowing for faster performance and scalability.
In these examples, I'm connecting remotely to the hypervisor from a Window 10 client. You will need to ensure that remote management has been configured on the hypervisor to be able to do this, while also ensuring the relevant Windows Firewall with Advanced Services rule(s) have been created to allow communication. It would also be prudent to ensure WinRM is also similarly configured.
If you didn't want to enable this remote functionality then you can run the same commandlets sans the -ComputerName parameter locally on the hypervisor, using a push approach to sending the data out to a collection point or data repository.
I'm deliberately leaving the database topic out of scope. It's enough to say it's definitely possible, but much as with pulling the data, there's more approaches to this than I can easily cover.
Cheers,
Lain
- ahinterlCopper Contributor
Thank you for the examples 🙂.