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:
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…