{"id":3296,"date":"2012-02-02T12:10:06","date_gmt":"2012-02-02T10:10:06","guid":{"rendered":"https:\/\/ingmarverheij.com\/?p=3296"},"modified":"2013-11-30T14:30:22","modified_gmt":"2013-11-30T13:30:22","slug":"connect-to-vm-without-xencenter","status":"publish","type":"post","link":"https:\/\/ingmarverheij.com\/en\/connect-to-vm-without-xencenter\/","title":{"rendered":"Connect to VM without XenCenter"},"content":{"rendered":"<p>Author: <a href=\"https:\/\/ingmarverheij.com\/\" target=\"_blank\">Ingmar Verheij<\/a><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; float: right; padding-top: 0px; border-width: 0px;\" title=\"\" alt=\"\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/Windows-7-desktop.jpg\" width=\"129\" height=\"83\" align=\"right\" border=\"0\" \/><\/p>\n<p>If you want to connect to the console of a virtual machine running on Citrix XenServer you either need XenCenter or the Web Self Service portal.<\/p>\n<p>I created a PowerShell script that connects to the console of the virtual machine, without the use of both. This script can be used to offer a shortcut to a virtual machine without requiring the user to have XenCenter installed, or having a XenServer Enterprise or Platinum license (it works with the free license).<\/p>\n<p><!--more--><\/p>\n<h4>VNC<\/h4>\n<p>XenServer uses <em>virtual network computing <\/em>(VNC) to connect to the console of a virtual machine. In this script I\u2019m using the <a href=\"https:\/\/www.tightvnc.com\/\" target=\"_blank\">TightVNC<\/a> viewer to connect to the console, but you can use any other VNC viewer (although it requires you to change the script and might give issues when used via Citrix ICA).<\/p>\n<h4><\/h4>\n<h4>SSH tunnel<\/h4>\n<p>The VNC connector on the XenServer only listens on the localhost, so you\u2019re unable to connect to it directly. Before you can connect your VNC viewer to the console you need to tunnel the data through an SSL tunnel. This will encapsulate all VNC data through a secured channel and deliver it on the XenServer. I\u2019m using plink (a component of the <a href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\" target=\"_blank\">PuTTY<\/a> suite) to send SSH commands and setup a SSL tunnel between the host and the XenServer host (just like XenCenter does when you connect to the console of a VM).<\/p>\n<p><em>Note: The sa2 key fingerprint is accepted automatically by the script. <\/em><\/p>\n<p><em>Note: I\u2019m aware there is a <a href=\"https:\/\/huddledmasses.org\/scriptable-ssh-from-powershell\/\" target=\"_blank\">Powershell cmdlet for SSH<\/a> (which could prevent the use of plink) but this cmdlet is unable to set up a SSL tunnel.<\/em><\/p>\n<h4><\/h4>\n<h4>Connect to who and where?<\/h4>\n<p>Before you can setup the SSL tunnel you need to know two thing. The XenServer the VM is running on (1) and the port the VNC server is running on (2). So before setting up the SSL tunnel I\u2019m querying the XenServer (pool master)\u00a0 for IP address of the XenServer host where the VM is running.<\/p>\n<p><em>The name of my virtual machine is \u2018WS01\u2019 and I added custom field \u2018STUDENT\u2019 with the value \u20181\u2019.<\/em><\/p>\n<pre>xe vm-list name-label=\"WS01\" other-config:XenCenter.CustomFields.STUDENT=1 os-version:distro=\"windows\" params=resident-on --minimal\r\nxe pif-list management=true params=IP host-uuid=(uuid of XenServer host) --minimal<\/pre>\n<p>Now I know the IP address of the XenServer where the VM is running I can search for the domain ID of the virtual machine. With the domain ID I can search for the VNC server process qemu-dm-&lt;domid&gt;.<\/p>\n<pre>xe vm-list name-label=\"WS01\" other-config:XenCenter.CustomFields.STUDENT=1 os-version:distro=\"windows\" params=dom-id --minimal\r\nnetstat -lp|grep -w $varDomPrefix(domID of the VM)|awk '{print $4}'|cut -d: -f2<\/pre>\n<p>Okay, so now I know the IP address of the XenServer where the VM is running (1) and the port where the VNC host is running (2).<\/p>\n<pre>plink -N \u2013L (VNC port):localhost:(VNC port) <a href=\"mailto:root@(IP\">root@(IP<\/a> Address of XenServer)<\/pre>\n<p>&nbsp;<\/p>\n<h4>Connecting though ICA (Citrix XenApp \/ XenDesktop)<\/h4>\n<p>I published the console of a virtual machine as a published application so my users can access the console from anywhere (via the CloudGateway). During testing I found out that both RealVNC and UltraVNC had performance issues, only TightVNC in 8-bit mode worked at a proper speed.<\/p>\n<p>If you don\u2019t want the connect in 8-bit mode, change the line <em>$vncUse8Bit=$true<\/em> to <em>$vncUse8Bit=$false<\/em>.<\/p>\n<h4>\u00a0<a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/Citrix-XenApp-Toepassingen-Windows-Internet-Explorer_2012-02-02_09-58-271.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"Published Application 'Workstation 1'\" alt=\"Published Application 'Workstation 1'\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/Citrix-XenApp-Toepassingen-Windows-Internet-Explorer_2012-02-02_09-58-27_thumb1.png\" width=\"179\" height=\"126\" border=\"0\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/CWindowssystem32WindowsPowerShellv1.0powershell1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"PowerShell\" alt=\"PowerShell\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/CWindowssystem32WindowsPowerShellv1.0powershell_thumb1.png\" width=\"179\" height=\"92\" border=\"0\" \/><\/a><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/QEMU-Remote_2012-02-02_11-28-121.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"Remote console via published application\" alt=\"Remote console via published application\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/QEMU-Remote_2012-02-02_11-28-12_thumb1.png\" width=\"179\" height=\"147\" border=\"0\" \/><\/a><\/h4>\n<h4><\/h4>\n<p>&nbsp;<\/p>\n<h4 id=\"download\">PowerShell script (this is where it\u2019s all about)<\/h4>\n<p>Download:\u00a0<a  data-e-Disable-Page-Transition=\"true\" class=\"download-link\" title=\"Version 1.0\" href=\"https:\/\/ingmarverheij.com\/en\/download\/5813\/?tmstv=1776524279\" rel=\"nofollow\" id=\"download-link-5813\" data-redirect=\"false\" >\n\tConsoleXSConnect.ps1<\/a>\n<\/p>\n<h4><\/h4>\n<p>&nbsp;<\/p>\n<h4>Usage<\/h4>\n<p>The script requires 4 arguments and has 2 optional arguments<\/p>\n<pre><strong>Usage<\/strong>\r\npowershell.exe .\\ConsoleConnect.ps1 (XenServerPoolMaster) (XenServerUsername) (XenServerPassword) (VMName) [CustomFieldName] [CustomFieldValue]\r\n\r\n<strong>Example<\/strong>\r\npowershell.exe .\\ConsoleConnect.ps1 172.16.1.1 root Passw0rd WS01 STUDENT 1<\/pre>\n<p>XenServerPoolMaster: The IP\/FQDN of the XenServer (pool master) host<\/p>\n<p>XenServerUsername: The username to connect to the XenServer<\/p>\n<p>XenServerPAssword: The password to connect to the XenServer<\/p>\n<p>VMName: The name of the virtual machine<\/p>\n<p>CustomFieldName (optional): The name of a custom field<\/p>\n<p>CustomFieldValue (optional): The value of the custom field<\/p>\n<p>&nbsp;<\/p>\n<p>The custom field can be used to uniquely identify a virtual machine if the name of the machine is reused. In my environment I cloned the virtual machine \u2018WS01\u2019 multiple times and added a CustomField \u2018STUDENT\u2019. For each student a virtual machine is published.<\/p>\n<p><a href=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/WS01-Properties_2012-02-02_11-38-16.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; margin: 0px 5px 0px 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;\" title=\"'WS01' Properties\" alt=\"'WS01' Properties\" src=\"https:\/\/ingmarverheij.com\/wp-content\/uploads\/2012\/02\/WS01-Properties_2012-02-02_11-38-16_thumb.png\" width=\"529\" height=\"357\" border=\"0\" \/><\/a>.<\/p>\n<p>&nbsp;<\/p>\n<h4>Additional downloads (required)<\/h4>\n<ul>\n<li><a href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/download.html\" target=\"_blank\">plink<\/a> (part of PuTTY suite)<\/li>\n<li><a href=\"https:\/\/www.tightvnc.com\/\" target=\"_blank\">TightVNC<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4>Additional information<\/h4>\n<ul>\n<li><a href=\"https:\/\/oldsite.precedence.co.uk\/nc\/putty.html\" target=\"_blank\">Using PuTTY under Windows to create an SSH tunnel<\/a><\/li>\n<li><a href=\"https:\/\/blogs.citrix.com\/2011\/02\/18\/using-vnc-to-connect-to-a-xenserver-vms-console\/\" target=\"_blank\">Using VNC to Connect to a XenServer VM\u2019s Console (Citrix Blogs)<\/a><\/li>\n<li><a href=\"https:\/\/support.citrix.com\/article\/CTX119906\" target=\"_blank\">CTX119906 &#8211; How to Set Up VNC Channels Using PuTTY<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Author: Ingmar Verheij If you want to connect to the console of a virtual machine running on Citrix XenServer you either need XenCenter or the Web Self Service portal. I created a PowerShell script that connects to the console of the virtual machine, without the use of both. This script can be used to offer [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[152,77],"tags":[667,402,672,401,669],"class_list":["post-3296","post","type-post","status-publish","format-standard","hentry","category-powershell","category-xenserver","tag-citrix","tag-cloudgateway","tag-powershell","tag-putty","tag-xenserver"],"_links":{"self":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/comments?post=3296"}],"version-history":[{"count":7,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3296\/revisions"}],"predecessor-version":[{"id":5896,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/posts\/3296\/revisions\/5896"}],"wp:attachment":[{"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/media?parent=3296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/categories?post=3296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ingmarverheij.com\/en\/wp-json\/wp\/v2\/tags?post=3296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}