NOTE: This script does not work with Storefont v3, click here for the updated script.
In a previous post, I shared a PowerShell script to launch a Published App from one or more servers. I originally wrote this script because one of my lab XenApp 6.5 servers would not launch a Published Application. When I investigated what the issue was I was unable to determine the cause. The IMA Service was started, ICA was listening and responding, there was no load issues, etc, etc. This server was basically healthy.
I eventually got this server running again by removing it from the farm and re-joining it. As it turns out, there was an easier fix, as I found out last week. I tried launching an app that was only published from this server, and again, failure. But wait, my script was not alerting me to any errors, Published Applications from the script were launching from this server. My Powershell Script to monitor a Citrix XenApp Farm's Health was reporting all healthy.
What I determined was, the Server had Blue Screened due to a driver used for mounting ISOs, which was SlySoft's Virtual CloneDrive. When the XenApp Server recovered, there was an error in the Application Event Log about the IMA Service. The Service could not connect to the Data Store (MSSQL), but it Started. I had never noticed this before so I did not troubleshoot IMA. Normally if the IMA Service cannot connect to the Data Store it does not start. I decided to just restart the IMA Service and see what happens. The Service started fine, connected to the Data Store (MSSQL) and the Application launched. So much for monitoring the IMA Service (I need to work on this, but IMA is dead, so I probably will not).
I surmised that directly launching an Application from a XenApp Server would not query the IMA and would not encounter an issue if the IMA service was screwed up. So, back to the drawing board on monitoring that an Application actually launches.
So I took to Google again to see what else I could find. I found this blog entry at Citrix; Automating the launch of HDX sessions through StoreFront (and NetScaler Gateway integrated with StoreFront). The script emulates a user utilizing a Internet Explorer to connect to StoreFront and launch a Published Application.
As usual, I took it to the next level. I added more feedback and logging as well as detecting errors and firing off an email if an error is detected. I also added logging how long it takes to launch the session, just like my previous script did.
Just like my previous script, this is meant to run as a Scheduled Task using a test user to launch one or more Published Applications (or Desktops). I left my ailing server in the error state while testing this script and I was alerted that the Published Application would not launch.
I schedule the script to run daily, once per hour, between 6AM and 6PM. If there is an error, I get an email with a summary of the issue.
Here are the requirements for the script:
- Citrix Receiver installed in the default location.
- Must be launched from an Elevated Administrator console of PowerShell x86. The 64 Bit Powershell will not work since the script is using Citrix Receiver, which is 32 bit, to verify a launch and log off the session.
- No other sessions should be connected/running before running the script. Any Receiver processes will be killed, so existing sessions will be disconnected.
- SiteURL should be part of the Intranet Zone or Trusted Site zone, set at Medium-Low security, in order to be able to download AND launch the ICA file without interaction. This can be done manually or via a GPO if this is not already the case.
- StoreFront 2.0 or higher or NetScaler Gateway, version 9.3 or higher.
- Changes in web.config under C:\inetpub\wwwroot\Citrix\<storename>Web\: autoLaunchDesktop to false, pluginAssistant to false.
- Currently works for desktops or already subscribed apps only.
- You can auto subscribe users to apps by setting "KEYWORDS:Auto" in the published app's description or make sure the apps have been subscribed to manually.
- This script does not support AppController at this time.
- In order for the script to interact with the ICO, it requires the following to be set in the registry:
- x64: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix\ICA Client\CCM
- x86: HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA Client\CCM
- AllowLiveMonitoring REG_DWORD 1
- AllowSimulationAPI REG_DWORD 1
Create some Apps to use with the Script
The first thing you should do, before scheduling the task, is to publish an application (or Desktop) from each server and assign it to your test user. What I mean by that is; if you have five servers, you will need to publish the App or Desktop five times, one for each server. I am not testing load balancing, I am testing to make sure each server launches the application correctly.
I chose Task Manager, but it can be any application, such as Command Prompt. The more lightweight the application the better, you do not want to put extra strain on your servers.
You can also use a Published Desktop but Desktops are more resource intensive and take a little longer to launch since it initializes the Explorer shell. With this in mind, you may need to extend the wait time for the Log off command by adding -TimeToWaitForLogoff to the command line. By default this is set to 15 seconds and a Desktop may not load within 15 seconds. I have noticed that using a Desktop can be problematic. It is not so much an issue with the Server but with CDViewer on the client. So I recommend using Task Manager or Command Prompt for the test.
Subscribe to Apps
The Apps need to be visible in order for the Script to launch them. You will need to log in to Storefront, as the Test User, manually and subscribed to the Apps. Alternatively, you can auto subscribe the Apps by setting "KEYWORDS:Auto" in the published app's description.
Schedule the Task
My Scheduled Task's Action looks like this:
Program/Script:
%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe
Add arguments:
-executionpolicy bypass -file c:\CitrixScript\SFLauncher2.ps1 -SiteURL "https://citrix.domain.com" -UserName "domaain\TestUser" -Password "TestUserPassword" -smtpServer "smtp.server.domain" -emailFrom "XenAppMon@domain.com" -emailTo "email@domain.com" -LogFilePath C:\CitrixScript -LogFileName SFLauncher.log "App1" "App2"
Start in:
C:\CitrixScript
Security options:
The user account needs to be an administrator on the client so PowerShell can be elevated. This does not need to be the Test User.
Use the option "Run whether user is logged on or not" and "Run with highest privileges".
Command Line Notes:
The Application(s) to be launched need to be at the end of the command line, separated by a space, like this: "App Server1" "App Server2"
Test from a Command Prompt:
If you want to test before Scheduling, open a Command Prompt as an Administrator (right click and choose "Run as Administrator")
To test the script, here is a sample command line:
%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -file c:\CitrixScript\SFLauncher2.ps1 -SiteURL "https://citrix.domain.com" -UserName "domaain\TestUser" -Password "TestUserPassword" -smtpServer "smtp.server.domain" -emailFrom "XenAppMon@domain.com" -emailTo "email@domain.com" -LogFilePath C:\CitrixScript -LogFileName SFLauncher.log "App Server1" "App Server2"
Here is a Screenshot of what the script looks like while it is running:

I have tested the script with Internet Explorer 11 and Citrix Receiver 14.1 on Windows 7. I have also tested it on Windows 10 Preview with Citrix Receiver 14.2.
Here is the script:
Please let me know what you think, and if you have a better way of doing this, in the comments section.
SFLauncher2.ps1.txt (36.4KB)