Showing posts with label Get-VMHost. Show all posts
Showing posts with label Get-VMHost. Show all posts

Wednesday, July 30, 2014

Part - 4 : PowerShell and Hyper-V : Connecting to Hyper-V Virtual Machines.

 

  1. Part 1 :  PowerShell and Hyper-V : Getting Started
  2. Part 2 :  PowerShell and Hyper-V : Virtual Switch
  3. Part 3 :  PowerShell and Hyper-V : Starting Virtual Machines

After running and starting Virtual Machines, we need to connect with them. We need to see the screen of the Virtual machines, so that we able to see "what's happening".

The most frequent way to connect to the virtual machines is to by using "Hyper-V Manager" , Right click on them and choose to "Connect" or select the virtual machine and then click on the "Connect" in the "Action Pane"

Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya

But, it's not making any sense, that we have started the virtual machine using PowerShell, now we have to use GUI of "Hyper-V Manager" to connect with our virtual machine.

Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya

Unfortunately, there seems no PowerShell cmdlet is there, by which we able to connect to virtual machine console.

Fortunately, there is small exe named as vmconnect.exe is available by which we can connect to the virtual machine.

If you type vmconnect.exe and hit enter, it will open a "Remote Desktop" type window, asking for server and Virtual machine name to connect.

Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya

If you want to see more parameters supported by vmconnect.exe , simple type vmconnect.exe /? and hit enter.

Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya

As we see in above screenshot, it seems that vmconnect.exe require majorly two thing to connect to the Virtual machine, first is "Hyper-V server" name and the second is name of the virtual machine which we need to connect to.

Let's connect to console in a semi- PowerShell way.

As we know that  we can get a Hyper-V server name using Get-VMHost cmdlet.

In the below command I am storing the  .Name value of Hyper-V server in to a $vmHostName variable.

$vmHostName = (Get-VMHost).Name

Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya


Execute the variable name and you can see the name of my Hyper-V server there.


Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya


Rest of everything is simple now, type the vmconnect.exe and then provide our $vmHostName variable and after that provide the name of the virtual machine , which we want to connect to, in my case it is "MediaWiki" , provide the name and hit enter.

vmconnect.exe $vmHostName "MediaWiki" 

Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya


Bingo!! We are connect to our virtual machine console.. yayay!!!


If you are looking for a good PowerShell function to make this more advance check this out : http://www.powershellmagazine.com/2012/10/11/connecting-to-hyper-v-virtual-machines-with-powershell/ a cool function written by our PowerShell Guru Shay Levy.


Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya


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


Aman Dhally, Manya Dhally, Manya Kaur, Manya Arora, Manya 


Thanks.


Aman Dhally



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


 


Facebook: https://www.facebook.com/100DoSI 



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”.

Monday, July 14, 2014

PowerShell and Hyper-V : Getting Started with Hyper-V and PowerShell


“ To live is the rarest thing in the world. Most people exist, that is all.― Oscar Wilde ”
After writing article on “Desired State Configuration”, I was thinking about topics on which I can write a similar article series.  Nothing was coming to my mind, as I already covered “Active Directory”, “Desired State configuration”, “DHCP”, “Event Viewer” and other topics.
As I use “Hyper-V” a lot, then I thought why not to write a 0 – 200 level series of articles on “Hyper-V”? to me it seems to be good idea J and I hope you may like it too.
I love "Hyper-v", before using "Hyper-V", I used to have "VMware Workstation" , but after migrating to windows 8.1 and start using "Hyper-V" I never used "VMware Workstation" again.
Let’s get started.
Prerequisites
·        Windows 8.1
·        Try to have at-least 4 GB of minimum Ram.
·        64 Bit processor

Yes, that’s all.
Step 1 :
Go to the BIOS Setting of your System / Laptop and enable Virtualisation.
photo
Step 2 :
    • Boot your System
    • Go to Control Panel
    • Click on "Programs and features"
    • Click on "Turn windows feature On of Off"
    • Select all features and sub features of "Hyper-V"
    • and Click on "OK"
    • 14-07-2014 15-09-49


Step 3 :
    • Open PowerShell Console.
    • There is no need to Import Hyper-V module , as after PowerShell v3, they all auto imported.
      Import-Module Hyper-V

    • 14-07-2014 14-38-13

    • To know the list of all cmdlets imported by Hyper-V module , you can run the simple command
      Get-Command -Module 'Hyper-V'

    • 14-07-2014 14-39-02





Step 4 :


Let's run basic cmdlets for now.




    • To get the list of "Hyper-V" hosts, run the cmdlet, Get-VMHost

    • 14-07-2014 14-40-06

    • If you want to see the list of all virtual machines, just run the cmdlet Get-VM.

    • 14-07-2014 14-40-28

    • and you can see that all of machines are Off. you can cross verify it  by open a Hyper-V management console. Smile 

    • 14-07-2014 14-40-53



That's all of now and hope to see you in next blog post.



Thanks & Regards

Aman Dhally

loki-2







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”.