Tome's Land of IT
IT Notes from the Powertoe – Tome Tanasovski
Category Archives: Hyper-V
Powerbits #8 – Opening a Hyper-V Console From PowerShell
March 13, 2012
Posted by on I am right now Windows Server 8 and PowerShell 3 Beta obsessed. I want to blog – I want to blog – I want to blog, but I’m trying to hold back a lot of it until we see how everything shakes out. I’m running Serer 8 beta on my new Asus ultrabook. Because of this, I’m also running a ton of Hyper-V VMs on my fancy type-1 hypervisor in order to play with the new features in PowerShell 3 such as PowerShell Web Access and disconnected PSSessions. I love the autoload of the Hyper-V module when I do something like Get-VM, but I was really disappointed that there was no cmdlet to open up a console session for one of my VMs. I mean, I have no interest in loading up a GUI for Hyper-V to do this. A bit of quick research led me to vmconnect.exe.
So, without further ado, here’s a quick wrapper that will let you open up Hyper-V console sessions directly from PowerShell. This is now permanently in my profile:
function Connect-VM { param( [Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)] [String[]]$ComputerName ) PROCESS { foreach ($name in $computername) { vmconnect localhost $name } } }
Now, you can either do something like
Connect-VM server2
or
'server2','server3'|connect-vm
Finally, if you are running PowerShell 3.0, you can do the following:
(get-vm).name |Connect-VM