This is one of the first post of a short blog series with some simple PowerShell scripts and oneliners for Hyper-V. One this is how you can connect a Virtual Network Adapter of a Hyper-V Virtual Machine to another Virtual Switch.
This is very simple, with this command you can see all the Network Adapters of the Virtual Machine and to which Switch they are connected:
Get-VM "VM01" | Get-VMNetworkAdapter
With this command you can connect it to another Switch:
Get-VM "VM01" | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "NewSwitch"
Now of course you can also do this for all Virtual Machines running on a Hyper-V host:
Get-VM | Get-VMNetworkAdapter Get-VM | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "NewSwitch" Get-VM | Get-VMNetworkAdapter