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")