Launching Virtual Machine Sessions from the Command Line with VMConnect

Illustration of a street view made up of binary values.
Do your virtual machine have this inside?
SOURCE: iStock

Whether you need to try a new operating system or run your software, using a virtual machine (VM) is a great option. But running a VM comes with a lot of issues. This is particularly true when dealing with multiple VMs hosted on a server with limited resources or when remote connections are disabled to enhance your network’s security. Windows RDP Client is often the go-to tool for troubleshooting problems with remote virtual machines. That said, another native tool you can use is called Virtual Machine Connection (VMConnect). This tool lets you use a computer’s local resources on a VM — and this can include using a removable USB stick or even a printer! 

In this article, I’ll show you what VMConnect is and what scenarios govern when you should use this tool. You’ll also learn how to use VMConnect to access a remote Hyper-V virtual machine. First, let’s take a look at why you should use VMConnect!

Why Use VMConnect?

You’d want to use VMConnect for many reasons when working with a VM. Perhaps the most important reason is that using VMConnect frees you from relying on the Windows Remote Display Protocol (RDP).

The RDP protocol definitely has its place but also has its shortcomings. For starters, not every VM should be remotely accessible. That’s due to the security risks related to the lack of privileges required to run the RDP program. Thus, administrators usually don’t enable the RDP protocol unless they have a compelling reason to do so. That means using RDP for troubleshooting purposes won’t always be an option.

A significant benefit of VMConnect over using a conventional RDP connection is the ability to use local resources. You can also control user activity by requiring them to sign into a VM using a smart card.

If the computer running VMConnect and the VM both meet the requirements, you can use any of the following local resources if they’re available:

  • Display configuration
  • Clipboards for copy and paste
  • Smart cards
  • USB devices
  • Audio
  • Printers
  • Drives
  • Plug-and-play devices

As an administrator of these local resources, you’ll benefit the most from the copy-and-paste functionality. This is especially true when conducting platform upgrades and migrations. You can copy and paste files to and from a VM like you would with a Remote Desktop Connection (RDP). 

Connected devices allow you to liaise with personnel on-site to connect data storage, for instance, and it’s exceptionally useful during data migration from older systems. 

You can troubleshoot developer applications requiring USB and sound redirection for software development without using RDP.

Now, let’s see how you can work with VMConnect. 

Working With VMConnect

VMConnect tends to be relatively basic and easy to use. That said, you can use several parameters to customize your experience and improve your productivity. To see the full command syntax and parameter list, enter the following command:

VMConnect /?

Screenshot of the VMConnect /? returned result displaying full command syntax.
Entering VMConnect /? Causes the full command syntax to be displayed.

We’ll discuss the connection method later. But here’s the syntax you use:

vmconnect.exe ServerName VMName [-C count]

vmconnect.exe ServerName [VMName] -G GUID [-C count]

In the above examples, -C or count variable allows you to state a VM instance ID if you want to launch more than one connection at a time. These automatically stack when each one is opened.

Another way of establishing a connection is to use the -G variable that allows you to use the globally unique identifier (GUID) of the VM you want to connect to. 

Pro Tip 

Use a GUID  to identify hardware, software, accounts, or other objects. A GUID is a 128-bit text string used to help represent and identify objects. Businesses often generate GUIDs when they need a unique reference to help identify something on the network. Administrators can make these human-readable or follow a naming rule set. 

Next up, I’ll explain how you can easily connect to it. 

Connecting the Easy Way

For those who are command line averse, you don’t have to enter any command line parameters. Simply entering the VMConnect command by itself causes a GUI to appear, the VMConnect window. This window prompts you to enter the name of the Hyper-V server and the name of the virtual machine that you want to connect to. 

Next, let’s learn how to bypass the dialog box.

Bypassing the Dialog Box

Entering the VMConnect command by itself is sufficient for establishing a connection to a remote VM. That said, you can also enter the Hyper-V server name and the VM as parameters. That keeps you from having to populate a dialog box. Instead, you’re taken directly to the remote session. This can be useful if you need to script a connection to a VM session. To supply a server name and a VM name, enter the following command:

VMConnect <server name> <virtual machine name>

Remember, you’ll need to replace <server name> with the actual name of your Hyper-V host. You’ll also need to replace <virtual machine name> with the name of the VM you want to connect to. If the VM’s name consists of multiple words, you’ll need to enclose its name in quotation marks. For example, to connect to a VM named Server Core on a host named Hyper-V, you would enter this command:

VMConnect Hyper-V “Server Core”

Screenshot of VMConnect connecting directly to the remote session.
VMConnect was able to connect directly to the remote session.

Supplying Credentials

The most important thing to know about this technique is that it only worked because I was signed in with an account that had access to the remote VM. That said, you can specify an alternate set of credentials if necessary. To do so, you must append a username and password to the command that I previously showed you. Here’s what the command looks like:

VMConnect <Server Name> <Virtual Machine Name> /user <user name> /password <password>

Again, you would replace <username> with the actual user name and replace <password> with your password.

Now that you have a few more tools in your VM toolkit, let’s wrap up.

Final Thoughts

VMConnect is a great tool for connecting to VMs in situations where RDP alone isn’t available or isn’t working. You can also use VMConnect if your VM is experiencing networking problems or when you’re worried about the security of your RDP in terms of the lack of permission required to create a successful connection. With the scripts I’ve shown, you can now easily connect, bypass the dialog box, and supply credentials.

Have more questions? Check out the FAQ and Resources sections below.  

FAQ

Is it possible to establish a VMConnect session in the absence of network connectivity?

Unless you’re running VMConnect locally, directly on the Hyper-V host where the VM resides, network connectivity is required. That said, the VM itself doesn’t require network connectivity. You only need to be able to connect to the Hyper-V host. That host will then provide the path to the VM.

How do I use my keyboard and mouse outside the remote session when using VMConnect?

Most of the time, you should be able to move your mouse freely between the remote session and your local operating system. That said, if the remote session does capture your keyboard and mouse, you can release them by pressing Ctrl + Alt + Left Arrow.

Is using VMConnect the best option if the VM runs on a host I access locally?

While you can use VMConnect in these situations, you don’t necessarily have to. If you would rather not work with a command line tool, you can access the VM’s console by using the Hyper-V Manager instead.

Can I access a remote VM’s console without using a command line tool?

If you have access to the Hyper-V Manager, you may be able to attach it to the remote host and then open the VM’s console that way. A better option is to use System Center VM Manager. This Microsoft tool displays your entire virtualized environment through a single console.

Why does Windows give me an error when I enter the VMConnect command?

It may be that Windows is having trouble finding the VMConnect.exe file. This file is normally located in the C:\Windows\System32 folder. The Hyper-V management tools may not be installed if the file is missing. It’s also worth noting that this file doesn’t exist on Windows servers that run a server core configuration.

Resources

TechGenix: Article on Changing The RDP Port

Learn how to change the Windows RDP port.

TechGenix: Article on RDP Sans Microsoft

Discover how to use RDP sans Microsoft.

TechGenix: Article on RDP Timeout Problems

Find out what you can do when timeout problems occur while initiating an RDP session.

Microsoft: Article on VMConnect Documentation

Discover more about VMConnect in Microsoft’s official documentation.

Microsoft: Article on Using Local Resources

Read more on how to use local resources on Hyper-V.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top