Recently I’ve been asked howto use PowerShell to modify the virtual switch setting on VMs.
Specifically they wanted to migrate 30+ IIS virtual machines from one virtual switch to another.
This was because since their configuration was that each VLAN has their own virtual switch on the Hyper-V hosts.
1 |
Get-VM -Name "*IIS*" | ForEach-Object {Connect-VMNetworkAdapter -VMName $_.Name -SwitchName "vSwitch VLAN901"} |
Why don’t I just use the pipe directly and avoid the ForEach all together?
The VMName parameter doesn’t take pipeline input 😉