Hyper-V Powershell Networking

Hyper-V Powershell Networking

Get a list of switches

Get-VMSwitch

Get a list of Network adapters

Get-VMNetworkAdapter -all

Change virtual switch each VM’s Network Card points at: –

Get-VM "VM01" | Get-VMNetworkAdapter

With this command, you can connect it to another Switch:

Get-VM "VM01" | Get-VMNetworkAdapter | Connect-VMNetworkAdapter -SwitchName "NewSwitch"

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

Reset a network adapter to use DHCP

# Return network interface to a variable for future use

$interface = Get-NetIPInterface -InterfaceAlias "Ethernet0" -AddressFamily IPv4

# Remove the static default gateway

$interface | Remove-NetRoute -AddressFamily IPv4 -Confirm:$false

# Set interface to "Obtain an IP address automatically"

$interface | Set-NetIPInterface -Dhcp Enabled

# Set interface to "Obtain DNS server address automatically"

$interface | Set-DnsClientServerAddress -ResetServerAddresses

Set IP Address

New-NetIPAddress -InterfaceAlias "Ethernet0" -AddressFamily IPv4 -IPAddress 192.168.1.xxx -PrefixLength 24 -DefaultGateway 192.168.1.1

Set DNS

Set-DnsClientServerAddress -InterfaceAlias "vEthernet (V10Network)" -ServerAddresses ("192.168.1.2","192.168.1.1")
Stephen

Hi, my name is Stephen Finchett. I have been a software engineer for over 30 years and worked on complex, business critical, multi-user systems for all of my career. For the last 15 years, I have been concentrating on web based solutions using the Microsoft Stack including ASP.Net, C#, TypeScript, SQL Server and running everything at scale within Kubernetes.

Finchett.com
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.