VDI Printing

For years, our computer lab network printing was based on a GPO applied to a container of computer objects in each physical location.  For each lab there was an OU (i.e. Location A) in AD, making it easy to restrict printer, application and other policies by a physical location.  If 20 machines were deployed in Location A, the Location A OU would have 20 computer objects.

We decide to virtualize Location A and then realize that our location based policy restrictions won’t work in their current form.  All virtual desktops are centralized in one location (i.e. Location Z) running off a grid of servers.  Additionally, our lab virtual desktop sessions are non-persistent, so computer objects are constantly created and destroyed.

In sum, our main problem with virtualizing Location A is this: How can my virtual desktop detect my physical location?

The answer is the IP address of the endpoint.  This value is stored in a registry key within the virtual desktop session here: HKLM\SOFTWARE\Citrix\Ica\Session\1\   The registry key provides the IP address of the user’s endpoint device (i.e. thin client, tablet, etc.).  From there, we created a PowerShell script to add printers based on the subnet of the endpoint IP address:

# Location of the scripts
$RunPath = "C:\Users\Public\Documents"
cd $RunPath

# Get IP of host (i.e. thin/fat client)
$IP = Get-ChildItem ‘hklm:\SOFTWARE\Citrix\Ica\Session\1\’ | Get-ItemProperty | Select-Object -ExpandProperty ClientAddress

# Determine building location based on IP subnet
# Run script for identified location
if ($IP.Contains(“192.168.2”) -or $IP.Contains(“192.168.3”) -or $IP.Contains(“192.168.4”) -or $IP.Contains(“192.168.5”))
{ LocationA }
elseif ($IP.Contains(“192.168.6”) -or $IP.Contains(“192.168.7”) -or $IP.Contains(“192.168.8”) -or $IP.Contains(“192.168.9”))
{ LocationB }

function LocationA
# Add LocationA printer
$LocationAPrinter = “\\PrintServer\Printer”
$net = new-Object -com WScript.Network

# Set Default Printer
function LocationB
# Add LocationB printer
$LocationBPrinter = “\\PrintServer\Printer”
$net = new-Object -com WScript.Network

# Set Default Printer

The SetDefaultPrinter line will override the existing default printer, even if printer pass-through via the ICA client is enabled.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s