Home > Blogs > VMware PowerCLI Blog


Opening the Virtual Machine Remote Console through PowerCLI

With the 5.5 R1 release PowerCLI got even better. With the introduction of the new Open-VMConsoleWindow cmdlet you can access the virtual machine console of both vCenter Server and vCloud Director virtual machines. To open a virtual machine console window, simply pass a powered-on virtual machine to the Open-VMConsoleWindow cmdlet:

Get-VM “Win2k3” | Open-VMConsoleWindow

As a result, the cmdlet opens a Web page containing the virtual machine remote console:

clip_image002

You can even open the console in full screen mode – either by specifying the corresponding cmdlet parameter or by clicking the Full Screenbutton on the Web page:

Open-VMConsoleWindow –VM “Win2k3” –FullScreen

Unless configured otherwise, the cmdlet opens the virtual machine console in the default Web browser on your machine. If you want to use a different browser, you can do so by specifying it in the PowerCLI configuration. You will need to specify the full path to the browser’s executable file:

Set-PowerCLIConfiguration –VMConsoleWindowBrowser “C:\Program Files (x86)\Mozilla Firefox\firefox.exe”

To switch back to using the default browser, simply specify “$null” for the “VMConsoleWindowBrowser” setting.

How does this work under the covers?

In order to display the virtual machine console, PowerCLI uses the VMRCbrowser plug-in embedded in a Web page. This plug-in is installed during the installation of PowerCLI. It supports 32-bit Internet Explorer, Mozilla Firefox, and Google Chrome browsers. The Web page is located at “<PowerCLI install dir>/VMConsoleWindow/” – have a look at it if you want to get the full details or make modifications.

Opening the virtual machine console requires authentication in the form of a token. For vSphere virtual machines this token is acquired through the “AcquireCloneTicket()” method of the SessionManager API object, and for vCloud Director – through the “AcquireTicket()” method of the VirtualMachine API object. In both cases the token is valid for 30 secondsfor single use. The token, virtual machine ID, and the host it’s running on (along with other parameters) are passed as URL parameters to the above-mentioned Web page. If you want to get hold of just this URL (for example, if you want to run Firefox with a specific profile) – you can do so by specifying the “UrlOnly” parameter:

$url = Open-VMConsoleWindow –VM “Win2k3” –UrlOnly

.”C:\Program Files (x86)\Mozilla Firefox\firefox.exe” -P Work $url

With this new cmdlet you now have one less reason to use the vSphere Web Client and can switch entirely to PowerCLI as a single tool for managing your entire virtual infrastructure! How cool is that!

Getting more from the Open-VMConsoleWindow

Another way in which this cmdlet can be used is to solve a common use case in virtual environments.  Often VM owners will want access to their console to troubleshoot an OS or to have the ability to enter the BIOS, this often leads to vSphere Administrators giving people access to the vSphere Web Client or vSphere Client.

As we know there are more actions than opening a console in the full clients and therefore these VM owners often get new ideas about features they would like to use but do not have permissions to do so.  With this cmdlet and other free tools we can easily give the users access to a console window to open their VM without them knowing about the full vSphere Clients.

An example of this is in the below video where we create a scripted application which we can send to our users in just 5 lines of code! Check it out…

clip_image002[8]This post was created by Dimitar Barfonchovski.Dimitar joined VMware and the PowerCLI team in 2007. He is member of the development part of the team and his main responsibilities are the functional design and implementation of features for the vSphere and vCloud PowerCLI components.

As with all members of the team, he is working to deliver a good and valuable product. He is also working to improve all processes and tools involved in the product development and validation.

This entry was posted in vCenter and tagged , , on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API's, SDK's and CLI's, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

24 thoughts on “Opening the Virtual Machine Remote Console through PowerCLI

  1. Pingback: Opening the Virtual Machine Remote Console through PowerCLI | VMware PowerCLI Blog – VMware Blogs | Tech Curator

  2. Trevor

    Hi, I’m playing around with this, and my script editor doesn’t like the “-OutputMode” switch after Out-GridView… Do I need to add a library or something?

    Reply
  3. Mitrajeet Howal

    is it Possible to terminate All IDLE Session which we always see under Seesion tab of vSphere Client with the help of Power CLi 5.5 ???
    i tried some script but it Terminating ACTIVE seesions also ..
    please share if you have any idea.

    Reply
      1. Mitra

        Hello Sir,

        The mentioned command in your article is “Get-VISession” but this command is not recognized by Power cli version 6.3 & old 5.5

        Output of the command is below for your reference :

        PowerCLI C:\Users\mycloudvra\Desktop> Get-VISession
        Get-VISession : The term ‘Get-VISession’ is not recognized as the name of a
        cmdlet, function, script file, or operable program. Check the spelling of the
        name, or if a path was included, verify that the path is correct and try again.
        At line:1 char:1
        +
        Kindly help

        Reply
  4. James Lin

    Quick question: are there ways to send keys (i.e. username/password) to the VMConsoleWindow object once we have the VM console window ready? Thanks in advance.

    Reply
  5. Chris B

    Although it is nice to open a console from powershell, the old VMware-vmrc.exe (version 4.0) works much better. It launches in seconds and gives you extra features like initiating reboots or mounting a CD to the VM. In our large vcenter environment, it takes over a minute to launch a console since it takes so long for it to connect to the vcenter. You can shorten this quite a bit by knowing which host the vm is on and directly connect to that host but still noticeably slower and provides less functionality than the old exe did. For now the old version of VMware -vmrc.exe still works with VMware 5.1 so we are continuing to use it to launch consoles instead of having to bring up a vSphere Client and drilling down to the vm. I hope you bring back a simple command line way of doing this again (and make it as fast and feature rich as the old version).

    Reply
  6. leoyyang

    Hi, Alan

    I am newly to Powercli automation, and this is really help me.
    Now in 5.1 we can open the vm console window, but is there any method that can send commands to the vm and get the response from vm through Powercli?
    If not, is there any other APIs that can do this?

    Reply
  7. Steve Bergen

    Thanks for the tutorial. It’s very useful for people on esxi 5.5 (VMware-vmrc.exe v4.0 doesn’t work for v10 hardware) and who are connecting from Windows 7 (we can’t install vCenter).

    I’ve tried to get back to a ‘single click’ solution to launching my vm’s. There’s probably an easier way to achieve this but…

    Create a new file called “Initialize-PowerCLIEnvironment_Custom.ps1”

    $server = “your.fqdn.or.ip”
    $protocol = “https”
    $usr = “your_usrename”
    $pwd = “your_password”

    Connect-VIServer $server -Protocol $protocol -User $usr -Password $pwd

    $vm = Read-Host ‘Load VM Console? VM Name or [Enter]:’
    if ($vm -ne “”) {
    Open-VMConsoleWindow -VM $vm -FullScreen
    }

    Place this file in the folder:
    C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts

    When you run the VMware vSphere PowerCLI command it will prompt you for the name of a VM to launch, otherwise just hit enter and you’re and the powershell prompt.

    It’s as close to ‘single-click’ as I can get.

    Reply
  8. Pingback: PowerCLI GUI for VM Consoles | rnelson0

  9. Hecktor

    Sadly this does not work using invoke-command. I have built a gui for some users that don’t have Powercli installed and it runs from a server does. Other cmdlets work but not this. Can it be made too?

    Reply
  10. Michael Aikens

    When I run the open-vmconsolewindow, I see a new session created on our vcenter server, but I cannot use disconnect-viserver to close the session. Is there anyway to close the session once the vm console window has been closed by the user and the script has completed? I know that I can run a scheduled task to get the current sessions and the disconnect them, but would like to see if the session can be closed once it is completed.

    Reply
  11. maddy

    HI,

    If i want to use the VMConsoleWindow.html page to open vcloud director console . in which format i should provide the input ? so that i can call the html page and pass inputs from the code

    Reply
  12. Pingback: Vmware Console | beautygoal.com

  13. Pingback: Vmware Console |

  14. Hauce

    Is anyone able to tell me if this specific cmdlet is the reason why the PowerCLI installation *requires* that VMware Remote Console Plugin 5.1 to be installed during setup?

    Reply
  15. Pingback: How To Access Virtual Storage Console | usahowto.com

Leave a Reply

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

*