In our first post, we started off with a nice and easy farm inventory script and had it send us an email report. Today, we’ll take a look at one of the most common issues we find when looking at customers’ environments: application inconsistency and forgotten applications. Tomorrow, we’ll start getting into some more advanced coding and look at ensuring server uptime using a scheduled PowerShell script. As always, please comment if you have any requests!

Now, since some environments have hundreds or thousands of apps published, some end up being accidentally disabled. Other apps might be published without users or servers, or the servers that are providing them might be removed from the farm. Another common issue I’ve seen at every client site I’ve ever been at: inconsistent application settings. There’s always at least one app that has different resolution, audio or encryption settings and as a result won’t do session sharing. That ends up causing a bad user experience (the user has to wait for the application session to start) and extra cost (the overhead of having an extra session running reduces server scalability). Neither are fun, and the fix is easy, if you can find the problem (and that’s exactly what this script does!)

Let’s walk through the script. The link to download the full script will be at the bottom of the post.

Step 1. Get the Application List

First, we’ll go ahead and get the application list that we’ll be running through. If we only want to look at a certain subset, this is where we would filter (by application name, folder name, or other characteristic). We also set the default app against which we’ll compare the other applications.

   $applications = Get-XAApplication  #Gets the published applications
    $default_app=$applications[0] #Sets the <span class="code-keyword">default</span> application to compare others again
    $disabled_apps=""
    $app_noservers=""
    $app_nousers=""




Step 2. Confirm Application Settings

In this code, we’ll loop through each application and go through the settings that would cause session sharing to not function. We’ll have the script report immediately if it finds an issue.

    foreach($app in $applications){
        #Checks to see <span class="code-keyword">if</span> the application settings are correct
        <span class="code-keyword">if</span>($app.ColorDepth -ne $default_app.ColorDepth){
            echo <span class="code-quote">"$app Color Depth does not match <span class="code-keyword">default</span> application."</span>
        }
        <span class="code-keyword">if</span>($app.WindowType -ne $default_app.WindowType){
            echo <span class="code-quote">"$app Window Type does not match <span class="code-keyword">default</span> application."</span>
        }    
        <span class="code-keyword">if</span>($app.EncryptionLevel -ne $default_app.EncryptionLevel){
            echo <span class="code-quote">"$app Encryption Level does not match <span class="code-keyword">default</span> application."</span>
        }    
        <span class="code-keyword">if</span>($app.EncryptionRequired -ne $default_app.EncryptionRequired){
            echo <span class="code-quote">"$app Encryption Required does not match <span class="code-keyword">default</span> application."</span>
        }    
        <span class="code-keyword">if</span>($app.AudioRequired -ne $default_app.AudioRequired){
            echo <span class="code-quote">"$app Audio Required does not match <span class="code-keyword">default</span> application."</span>
        }
        <span class="code-keyword">if</span>($app.AudioType -ne $default_app.AudioType){
            echo <span class="code-quote">"$app Audio Type does not match <span class="code-keyword">default</span> application."</span>
        }
        <span class="code-keyword">if</span>($app.AccessSessionConditionsEnabled -ne $default_app.AccessSessionConditionsEnabled){
            echo <span class="code-quote">"$app access control settings <span class="code-keyword">do</span> not match <span class="code-keyword">default</span> application."</span>
        }




Step 3. Is It Enabled?

Now we should also confirm if the application is enabled or not. Some applications may have been disabled for testing, others because all the servers were unassigned or removed from the farm. As a result, users can’t get to it – and even worse, if it’s not hidden, they’ll get a generic message telling them they’re not allowed to use it! ACK!








In the following section of code, we check to see whether the app is disabled, and then whether it has users or servers assigned to it. To keep the information from getting lost in the shuffle, we’ll add them to strings and give the output later, once we’ve cycled through all of the applications. Note: this script does not check to see if the servers are online.



       #Check to see <span class="code-keyword">if</span> the application is enabled or disabled
        <span class="code-keyword">if</span>($app.Enabled -eq 0){
            $disabled_apps+= <span class="code-quote">"$app is currently disabled.`n"</span>
        }
       
        #Check to see <span class="code-keyword">if</span> it's disabled because the app has no servers attached to it
        $servers = Get-XAServer -BrowserName $app.BrowserName
        <span class="code-keyword">if</span>($servers -eq $<span class="code-keyword">null</span>){
            $app_noservers+= <span class="code-quote">"$app currently has no servers assigned to it."</span>
        }
       
        #Check to see <span class="code-keyword">if</span> it's disabled because the app has no users allowed    
        $users = Get-XAAccount -BrowserName $app.BrowserName
        <span class="code-keyword">if</span>($users -eq $<span class="code-keyword">null</span>){
            $app_nousers+=<span class="code-quote">"$app currently has no users assigned to it."</span>
        }
    }
   


Step 4. Output the Results

We’ve already sent out the information on the application inconsistency to the console, so let’s go ahead and output the rest of the information that we’ve captured. Nice and easy:

    echo <span class="code-quote">"`nDisabled applications: "</span>
    echo $disabled_apps
    
    echo <span class="code-quote">"`nApps assigned to no servers: "</span>
    echo $app_noservers
    
    echo <span class="code-quote">"`nApps assigned to no users: "</span>
    echo $app_nouser




Step 5. Get the Code
To get the code, you can download it from the XenApp Code Share site, or use the direct link here.

Step 6. Read more…

More posts are going up the rest of the week – if you want to learn more, keep watch on the Citrix blogs, follow me on Twitter (@mcbogo), and sign up for next week’s TechTalk that will go over both XenApp and XenDesktop programming. Go sign up for the Essentials for using Windows PowerShell with XenApp and XenDesktop set for Tuesday, August 24 from 2pm to 3pm EST. And if you’re interested in PowerShell scripting for XenDesktop, go check out Ed York’s XenDesktop blog series.