Tuesday, July 22, 2014

Part - 2 : PowerShell and Hyper-V : Managing Hyper-V Virtual Switch

1. Part 1 :  PowerShell and Hyper-V : Getting Started
"Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.- Dr. Seuss"
In my previous post, we have seen the basic of "PowerShell and Hyper-V". That shows how to install Hyper-V and how to get the list of all virtual machines (those were pre-created).
Today, we are going create a new virtual switch.
What is a virtual switch?
In a simple language, it is virtual switch is virtual like virtual machines. Our Virtual machines need to connect with either each other, or with our physical machines, By using virtual switch, we can create a LAN environment.  We can created multiple LAN environment using these Virtual switches.
There are 3 types of virtual switches.
  1. External
  2. Internal
  3. Private
External :
In external switch, our virtual machine is able to talk with all of resources available on our physical network.
Internal :
Using internal switch, our virtual machine is only able to talk with the host and other virtual machines.
Private switch allow communication between the virtual machines on the host that's all.
Let's get started.
I am going to create a new External virtual switch.
Hyper-V external virtual switches are  bind on the physical lan/wifi adapter by which they can connected to physical environment.
To get the list of all network adapters we can use  Get-NetAdapter cmdlet.

22-07-2014 15-45-20
22-07-2014 15-44-39
 I am connected to my physical network using my LAN card named as "Ethernet". I will bind "Virtual External Switch" on "Ethernet" lan.
To create a new virtual switch we use New-VMSwitch cmdlet.
To list all of your Virtual switches, use the cmdlet,Get-VMSwitch
You can see that, currently, there is no virtual switch which is connected to External network.,
22-07-2014 15-49-26
22-07-2014 15-47-37

Creating external switch is simple. We just need to name of the External virtual swtich, and then name of our LAN/WiFI adapter name and that's all.
The command is : 
New-VMSwitch -Name "Connect_toThe_World" -NetAdapterName 'Ethernet' -AllowManagementOS $true

22-07-2014 15-48-12

And you can see that , new External Switch is created.

22-07-2014 17-41-38

If you want to create an internal or private switch, you mainly need two parameters with New-VMSwitch cmdlet, -Name and -SwitchType

Creating Internal virtual switch.
 New-VMSwitch -Name "my_lonely_world" -SwitchType Internal
22-07-2014 18-24-21

Creating Private virtual switch.

New-VMSwitch -Name "I_M_Secret" -SwitchType Private

22-07-2014 18-27-01

and you can see the list of all virtual switches.

22-07-2014 18-27-59

That's all for now Smile See you in my next blog posts.



Aman Dhally

Come and join my journey of : “100 Days of Self Improvement” on

If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

No comments:

Post a Comment