Wednesday, March 23, 2016

Powershell Rocks - Creating virtual Nic cards for testing (Standalone HyperV)

Today I had to setup some demo lab environment for my friend for tutoring purpose. He had couple of old desktop and Laptop with low configurations and one manageable old switch and router, I intended to install Windows server 2012 R2 on them and wanted to show standalone HyperV Demo. I installed and setup server everything was working fine but I wanted to show him HyperV Microsoft Failover Clustering but unable to simulate it, why because all those couple of desktops and laptop had only one NIC card and I required another Network Card for heartbeat purpose. but we didn't want to invest anything on the old. so here Powershell came to our rescue.
In windows server 2012 R2 when installed Hyperv Role and Powershell module, there is a feature you can create multiple virtual ethernet card, and all the traffic flows through single physical network card. Here I wanted to achieve my physical and virtual network card configuration like below diagram, HyperV role must be installed is requirement and Switch port where physical Nic is connected must be trunk if you want to use different subnets. 
Here are the Powershell commands with there parameters I used to setup and configure virtual network cards. First rule open Powershell as administrator.
Note: Running second command in the line can cause server disconnection. hence advised to not use remote desktop instead use ILO, DRAC or make sure you are in the front of server.
##*************************************************************************
Get-NetAdapter
New-NetLbfoTeam -Name "SwTeam" -TeamMembers PhysicalNic -TeamingMode Static -Confirm:$false
New-VMSwitch "VirtualSwitch" -MinimumBandwidthMode weight -NetAdapterName "SwTeam" -AllowManagement $false
Add-VMNetworkAdapter -ManagementOS -Name "Management" -SwitchName "VirtualSwitch"
Set-VMNetworkAdapter -ManagementOS -Name "Management" -MinimumBandwidthWeight 33
Add-VMNetworkAdapter -ManagementOS -Name "HeartBeat" -SwitchName "VirtualSwitch"
Set-VMNetworkAdapter -ManagementOS -Name "HeartBeat" -MinimumBandwidthWeight 33
Add-VMNetworkAdapter -ManagementOS -Name "Storage" -SwitchName "VirtualSwitch"
Set-VMNetworkAdapter -ManagementOS -Name "Storage" -MinimumBandwidthWeight 33
Get-VMNetworkAdapter -All -Name *
Get-NetAdapter
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "Management" -Access -VlanID 5
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "HeartBeat" -Access -VlanID 10
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "Storage" -Access -VlanID 20
Get-VMNetworkAdapterVlan -ManagementOS
##*************************************************************************

Now I will be running one command at a time and whatever I will be setting parameters based on results. First I will be running Get-Netadapter which shows all the Ethernet cards on the my system. As you can see from below screenshot I got only one Physical NIC and it is named as "PhysicalNic", Which I will be require in my next cmdlets.
Now I know, What is my Physical Nic name is, which I am going to use it in next command
Note: Running this command can cause server disconnection. hence advised to not use remote desktop instead use ILO, DRAC, or make sure you are in the front of server.
New-NetLbfoTeam -Name "SwTeam" -TeamMembers PhysicalNic -TeamingMode Static -Confirm:$false
It has created new software switch "SwTeam" and PhysicalNic is part of the Team, Static is the Teaming mode I am using here.
Tip: Incase you have installed HyperV but you are not able to find above command or next command I am going to run below command to install hyperv feature before starting command. HyperV role must be installed before running above commands. 
Install-WindowsFeature Hyper-V-PowerShell
New-VMSwitch "VirtualSwitch" -MinimumBandwidthMode weight -NetAdapterName "SwTeam" -AllowManagement $false
New-VMSwitch cmdlet creates a new virtual switch on one or more virtual machine hosts, Parameter minimumbandwidthMode is weight (weight is a unit (1 to 100) which i will be using in next command.)
Next I will be adding Virtual Network card and to the Host. and it will be using 33 % bandwidth weight of Physical nic. ManagementOS is your main operating system.
Add-VMNetworkAdapter -ManagementOS -Name "Management" -SwitchName "VirtualSwitch"
Set-VMNetworkAdapter -ManagementOS -Name "Management" -MinimumBandwidthWeight 33
Here is next screenshot after creating all the virtual nic cards. 
Next command to verify again what we have deployed. 
Get-VMNetworkAdapter -All -Name *
Get-NetAdapter
The last command is setting Vlan. and verify what settings has been configured. You can change below parameters as per your requirements. 
Tip: Incase you don't have trunk port(I mean your computers are connected to normal switches), do not run below commands, just assign IP directly.
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "Management" -Access -VlanID 5
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "HeartBeat" -Access -VlanID 10
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "Storage" -Access -VlanID 20
Get-VMNetworkAdapterVlan -ManagementOS
Now the last step is assign IP to virtual network cards and verify you can connect them over network, here I will assign IP on Management Network and just will check whether I am able to do RDP to the server. And I am Successful.


2 comments:

JacobHarman said...

The essential distinction among you and your prime supporter will be in the space of liability. You can be accountable for advertising, getting financial backers, and drawing clients — while your accomplice controls the item improvement process. On the off chance that you are keen on the most proficient method to find a tech prime supporter, we have an idea for you. Eastern Europe, especially Ukraine, is a decent spot to find startup accomplices. Here are only three fruitful organizations with Ukrainian tech fellow benefactors: It is a Ukrainian application that permits clients to supplant faces in recordings or GIFs through artificial intelligence/ML innovations. The prime supporters are Denys Dmytrenko, Oles Petriv, Ivan Altsybieiev, Roman Mogylnyi, Yaroslav Boiko, Dima Shvets, and Kyrylo Syhyda>> how to find startup partners

John Fei said...

At Attract Group, the custom software development services offered are truly exceptional. Their team of experienced professionals is dedicated to creating innovative solutions tailored to meet the unique needs of each client. From initial concept to final product delivery, their attention to detail and commitment to excellence shines through. The diverse range of services available, combined with a customer-centric approach, makes Attract Group a top choice for businesses looking to harness the power of customized software solutions.