Hyper-V Network Cheat sheet.
Hi
https://portal.nutanix.com/kb/000001553
For those who do not have access to Nutanix KB’s, I’m pasting few useful powershell commands for Hyper-V network management.
To list all the network adapters, type:
get-netadapterTo set something on the network adapter, type:
set-netadapterThis structure of the Hyper-V commands works anywhere in Windows PowerShell. Remember this structure and you can use most of the Hyper-V commands. You can also use the Tab key to complete the commands. The tab-completion tool not just completes commands, but also looks through all possible completions. This makes it easy to figure out the flags. Use the Get-help command to access the man pages.
In a CMD window, type powershell to access Windows PowerShell. If you are in Windows PowerShell, your prompt string starts with PS.
If you accidentally close all the CMD windows, press ctrl+alt+del and go to the task manager to open a new CMD window.
Following is a list of some useful Hyper-V commands.
Network Adapter Commands
get-netadapter get-vmnetworkadapter -managementOS get-vmnetworkadapter pVM Name] get-vmswitch add-vmnetworkadapter -managementOS set-vmnetworkadaptervlan get-netadapteradvancedproperty connect-vmnetworkadapter disconnect-vmnetworkadapter disable-VmNetworkAdapterNetadapter Team Commands
get-netlbfoteam get-netlbfoteammember new-netlbfoteam add-netlbfoteammember Remove-NetLbfoTeamMember m-Name] <Stringt]> &-Team] <Stringt]> &-CimSession <CimSessions]>] g-ThrottleLimit <Int32>] g-AsJob] J-PassThru] h-WhatIf] t-Confirm] i<CommonParameters>]Network Troubleshooting Commands
get-netadapterstatus netsh interface ipv4 show ipstats netsh interface ipv4 show tcpstatsSee the driver events. This is for the 10 GbE adapter.
get-winevent -providername ixgbn get-winevent -providername I*network*
Get the VMs on a host.
get-vmGet the VMs from SCVMM.
get-scvirtualmachineFor System Center, all the commands are in the naction]-scoobject] format. This is the same as using SSH in ESXi.
enter-pssession
Checking and Setting the Jumbo FramesRun the following commands to check and set the jumbo frames.
get-NetAdapterAdvancedProperty -DisplayName “Jumbo Packet” | format-table Name, RegistryValue set-NetAdapterAdvancedProperty -Name “Ethernet X” -DisplayName “Jumbo Packet” -RegistryValue 9014
Recreating the NIC TeamRun the following commands to recreate the NIC team.
Get the current adapters in the system.
get-NetAdapterCreate a new team.
new-NetLBFOTeam -Name NetAdapterTeam -TeamMembers @(“Ethernet X”, “Ethernet Y”)Replace X and Y with the numbers you obtained from the previous command. The @() represents an array.
Connect the team to the ExternalSwitch.
set-VMSwitch -SwitchName ExternalSwitch -NetAdapterName NetAdapterTeamTagging the External Network
Run the following commands to tag the external network.
Check the current settings.
get-VMNetworkAdapterVlanSet the Hyper-V host to use the correct VLAN.
set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "ExternalSwitch" -Access -VlanID {xx}Replace {xx} with your VLAN ID.
Set the Controller VM to use the correct VLAN.
set-VMNetworkAdapterVlan -Access -VMNetworkAdapterName "External" -VMName {xxx} -VlanID {xx}Replace {xx} with your VLAN ID.
Note: in case you need to undo a tagging, access via IPMI would allow the following command(s) to be entered:
Host:set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "ExternalSwitch" -UntaggedCVM:
set-VMNetworkAdapterVlan -Access -VMNetworkAdapterName "External" -VMName {xxx} -UntaggedRecreating the ExternalSwitch
Run the following commands to recreate the ExternalSwitch.
Get a list of the network adapters.
get-netadapterCreate a new switch.
new-vmswitch -Name ExternalSwitch -AllowManagementOS $true -NetAdapterName {name from above}Replace {name from above} with the name of the interface obtained from the previous command (get-netadapter).
Connect the Controller VM to the ExternalSwitch.
Connect-VMNetworkAdapter -VMName NTNX* -SwitchName ExternalSwitch -Name ExternalIf required, tag the VLAN on the Hyper-V host and the Controller VM.
set-VMNetworkAdapterVlan -ManagementOS -Access -VlanID {xx} set-VMNetworkAdapterVlan -Name NTNX* -Access -VlanID {xx}Set the jumbo frames. Repeat this step for the external vEthernet and the other Ethernet interface.
set-NetAdapterAdvancedProperty -Name “Ethernet X” -DisplayName “Jumbo Packet” -RegistryValue 9014Use sconfig to configure the IP address. Select the option 8 in the menu that appears to configure the IP address.
Verify the settings.
get-vmswitch get-vmnetworkadapter get-vmnetworkadaptervlan get-vmnetworkadapteradvancedpropertyRecreating the InternalSwitch
Run the following commands to recreate the InternalSwitch.
Create the switch.
new-vmswitch -Name InternalSwitch -SwitchType InternalConnect the internal adapter to the network.
Connect-VMNetworkAdapter -VMName NTNX* -SwitchName InternalSwitch -Name Internal- Use sconfig to configure the IP address. Select the option 8 in the menu that appears to configure the IP address.
Verify the settings.
get-vmswitch get-vmnetworkadapterAdding and Removing the NICs from the NIC Team
Run the following commands to add and remove the NICs from the NIC team.
List all the NICs attached to a NIC team and adapters in the system.
get-NetLbfoTeamMember get-NetAdapter get-NetLbfoTeamRemove a member from the team.
remove-NetLbfoTeamMember -Name “Ethernet X” -Team “TeamName”Add a member to the team.
add-NetLbfoTeamMember -Name “Ethernet X” -Team “TeamName”Connect the internal adapter to the network.
Connect-VMNetworkAdapter -VMName NTNX* -SwitchName InternalSwitch -Name InternalUse sconfig to configure the IP address. Select the option 8 in the menu that appears to configure the IP address.
Verify the settings.
get-vmswitch get-vmnetworkadapter
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.