- Part 1 : PowerShell and Hyper-V : Getting Started
- Part 2 : PowerShell and Hyper-V : Virtual Switch
- 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"
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.
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.
If you want to see more parameters supported by vmconnect.exe , simple type vmconnect.exe /? and hit enter.
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
Execute the variable name and you can see the name of my Hyper-V server there.
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"
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.
That's all for now. See you in my next blog post.
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”.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.