question

Doria avatar image
0 Votes"
Doria asked Doria commented

Select the virtual switch using PS.

Hi everyone!

How can I make in PS (PowerShell) the image action?

116881-image.png




Select the virtual switch for the VM.


Thanks.

windows-server-powershell
image.png (75.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarkE-5319 avatar image
0 Votes"
MarkE-5319 answered Doria commented

Use

Connect-VMNetworkAdapter -vmname <VMName> -Name <NetworkAdapterName> -switchname <Switchname>

So for a VM called test with a NIC called NIC1 connecting to ExternalNetwork

Connect-VMNetworkAdapter -vmname test -Name NIC1 -switchname ExternalNetwork

If you don’t know the name of the network adapter use;

Get-VMNetworkAdapter -vmname test

to get a list of adapters for that VM

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks all!

0 Votes 0 ·
ElevenYu-MSFT avatar image
0 Votes"
ElevenYu-MSFT answered

Hi,

If you would like to connect a virtual switch to a VM by PowerShell, you could use Connect-VMNetworkAdapter command.
For your reference: https://docs.microsoft.com/en-us/powershell/module/hyper-v/connect-vmnetworkadapter?view=windowsserver2019-ps

If you would like to disconnect a virtual switch by PowerShell, you could use Disconnect-VMNetworkAdapter command.
For your reference: https://docs.microsoft.com/en-us/powershell/module/hyper-v/disconnect-vmnetworkadapter?view=windowsserver2019-ps

If you would like to get virtual switches from the Hyper-V host, you could use Get-VMSwitch command.
For your reference: https://docs.microsoft.com/en-us/powershell/module/hyper-v/get-vmswitch?view=windowsserver2019-ps

If you would like to create a new switch, you could use New-VMSwitch command.
For your reference: https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/get-started/create-a-virtual-switch-for-hyper-v-virtual-machines#create-a-virtual-switch-by-using-windows-powershell

If you would like to create a new VM with specific switch, you could use New-VM -Name <Name> -MemoryStartupBytes <Memory> -BootDevice <BootDevice> -VHDPath <VHDPath> -Path <Path> -Generation <Generation> -Switch <SwitchName>
For your reference: https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/get-started/create-a-virtual-machine-in-hyper-v#create-a-virtual-machine-by-using-windows-powershell

Hope above information could help you.

Thanks,


If the Answer is helpful, please click "Accept Answer" and upvote it. Thanks.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.