Google Reviews
If you find this content or our services useful, please leave us a review.

We needed to configure VMWare Horizon client connections for different groups of users in an organisation.  Unfortunately the ADMX file didn’t support this configuration, so we needed to implement it using PowerShell.

When we looked at the VMWare Horizon view client ADMX there is a configuration called ServerURL:

VMWare Horizon Client ServerURL
A couple of things to mention on this policy object is that firstly, it only permits one URL!  Bummer.  The second drawback is that if you set this, your VMWare Horizon Client will be locked down to this single server URL, and hence prevents users from adding any other server URLs manually via the ‘New Server’ button!  Double bummer!

Needless to say, for these reasons we didn’t set this via policy.  However, we did set the MRBroker registry entry using policy (via a manual registry configuration):

HKLM\SOFTWARE\WOW6432Node\VMware, Inc.\VMware VDM\Client\MRBroker

This provided the default server we required without locking down the setting in the GUI.  And then to add additional servers, we used a PowerShell script based on AD group memberships which ran as a login script:

#Add connections to VMWare Horizon Client
#We launch as a separate job so there is no delay in login script processing


try {

	    $file = ($env:APPDATA)+"\VMware\VMware Horizon View Client\prefs.txt"

	    if (Test-Path -Path $file) {
		    [xml] $configxml = Get-Content ($file)
	
		    #remove references to view.alkane from recent connections
		    $xmlpath = '//Root/RecentServer[@serverName="view.alkane.co.uk"]'
		    $node = $configxml.root.SelectSingleNode($xmlpath)
		    if ($node -ne $null)
		    {
    			    $configxml.Root.RemoveChild($node)
    			    $configxml.Save($file)
		    }

		    #ensure serverName is not view.alkane, but newview.alkane
		    $xmlpath = '//Root/GlobalDefaultServer[@serverName="view.alkane.co.uk"]'
		    $node = $configxml.root.SelectSingleNode($xmlpath)
		    if ($node -ne $null)
		    {
    			    $node.SetAttribute("serverName", "newview.alkane.co.uk");
    			    $configxml.Save($file)
		    }
	    }

	    #path to view agent - used to add new connections
    	    $vmwareView = "$env:ProgramFiles (x86)\VMware\VMware Horizon View Client\vmware-view.exe"

	    if (Test-Path -Path $vmwareView) {

		    #add default connection to newview.alkane
                    #launching as hidden and unattended will add server to %AppData%\VMware\VMware Horizon View Client\prefs.xml
		    Start-Process -WindowStyle hidden -Wait -FilePath $vmwareView -ArgumentList @("-serverUrl","newview.alkane.co.uk","-unattended") -ErrorAction SilentlyContinue

	    }

} catch {}

In this PowerShell script the two key elements are:

  • We needed to strip out unwanted servers manually by navigating the XML DOM for %AppData%\VMware\VMware Horizon View Client\prefs.txt"
  • We needed to add new servers by calling C:\Program Files (x86)\VMware\VMware Horizon View Client\vmware-view.exe". We used the exe to do this as opposed to manually adding to the XML DOM because the exe also generates temporary folders with random GUID names (and populates XML attributes with this path), and it just felt the more ‘supported’ option to use the exe to handle this instead.
Configure VMWare Horizon Client Connections
Comments have now been disabled. If you have a question to ask about this post please ask the community!