[Last Call] Learn how to a build a cloud-first strategyRegister Now


PowerShell to create HTML report to list XenApp Servers with Load Evaluators

Posted on 2011-04-30
Medium Priority
Last Modified: 2012-05-11
We are using XenApp 5.0 environment having almost 150 XenApp servers. We are in the process of creating HTML report using PowerShell. The HTML report should show the "Server Name" and "Load Evaluator" name for those servers which are not having "Advanced" Load Evaluator applied.

I created the following script to do that.
Add-PSSnapin citrix.XenApp.Commands

$servers = Get-XAZone | Get-XAServer -OnlineOnly

Clear-Content $log_file

$htmlFilePath = "D:\LoadEvaluatorReport.html"
$strOutputString  | out-file -filepath $htmlFilePath -encoding ascii
$strOutputString  | out-file -filepath $htmlFilePath -encoding ascii -append

# Create HTML Output 
$strOutPut01 = "<center><table border=4><tr><td width=50000 align=center bgcolor=lightblue><h2>" + "Servers Without Advanced Load Evaluator" + "</h2></td></tr></table></center><br><br>"
# Write HTML to File    	
$strOutPut01 | out-file -filepath $htmlFilePath -encoding ascii -append

Get-XAServerLoad $servers | where-object {$_.LoadEvaluatorName -notcontains "Advanced"} | Select-Object ServerName, LoadEvaluatorName >> $log_file
Get-Content $log_file
Get-Content -readcount 100 -totalcount 100000 $log_file | ForEach-Object { $_ } | foreach { $_ -replace "ServerName", "Server Name"}| foreach { $_ -replace "LoadEvaluatorName", "Load Evaluator"} > D:\LoadEvaluator.csv
$CSVContents = Get-Content -Path D:\LoadEvaluator.csv

ForEach ($line in $CSVContents) 
	$strOutPut02 = "$line" + "<br>"
	$strOutPut02 | out-file -filepath $htmlFilePath -encoding ascii -append 

ii D:\LoadEvaluatorReport.html

Open in new window

This script will store the data in a LOG file ("LoadEvaluator.log"), then the log file will be converted to CSV file ("LoadEvaluator.csv") and the content of the CSV file will be displayed in the HTML file ("LoadEvaluatorReport.html"). Please see the attached files.

The HTML report is not showing the desired output in a well-formatted manner. The output is showing without any spaces between two columns (please see the attached html file).

It would be very much helpful for me if you could provide the code that will show the html output in a well-defined format as shown below:

Server Name              Load Evaluator
----------------              -------------------
XenApp1                     Default
XenApp2                     Disable ICA
XenApp3                     XenApp Custom Advanced

Question by:hchabria
  • 4
  • 2

Accepted Solution

robertkennedy earned 1000 total points
ID: 35497656
The following line writes this data out to the HTML file:
$strOutPut01 | out-file -filepath $htmlFilePath -encoding ascii -append

You would need to mark this up into a HTML table, I believe you may be able to pipe to a format-table which may also display this in a nicer format.

Author Comment

ID: 35497831
I am not that much of expert in PowerShell. However, I tried with format-table, but there is no result. It would be very helpful for me if you could modify my existing code with the your preferred code and give me the complete code snippet.

Assisted Solution

robertkennedy earned 1000 total points
ID: 35499246
Sorry it is difficult for me to do much here as i dont have that snapin installed and am not able to get the results directly from your servers however a couple of things I have noticed which may help you.

The csv file that is produced is not formatted correctly, i.e the data is not split between the columns correctly. You may like to look at piping line 20 into Export-CSV as follows:

Get-Content -readcount 100 -totalcount 100000 $log_file | ForEach-Object { $_ } | foreach { $_ -replace "ServerName", "Server Name"}| foreach { $_ -replace "LoadEvaluatorName", "Load Evaluator"} | format-csv D:\LoadEvaluator.csv

Then when you open the csv file and loop through to create the html you can split the line data based on the comma's and mark it up into html:

ForEach ($line in $CSVContents)
      $lineArray = $line.split(",")
                     $serverName = $lineArray[0]
                     $loadEvaluator = $lineArray[1]
                     $strOutPut02 = "<tr><td>" +$serverName+ "</td><td>"+$loadEvaluator+ "</td></tr>"
      $strOutPut02 | out-file -filepath $htmlFilePath -encoding ascii -append

** you will also need to write out "<table><tr><td>Server Name</td><td>Load Evaluator</td></tr>" as your header and "</table>" at the end of the loop.
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.


Expert Comment

ID: 35503117
As per Roberts comment, i too do not have the snapins, however reding your code it appears you have not formated any of the lines as html so that is why there is no formating when you launch the html file.

May I suggest you change your For loop with something like this.
$CSVContents | ConvertTo-HTML -Fragment | out-file -filepath $htmlFilePath -encoding ascii -append 

Open in new window

I can also see that you have created a single row table for the heading. Just do a H1 heading instead.
Tables shouldn't be used for formatting.

Author Comment

ID: 35715877

Sorry for my late response. However, none of the codes suggested could help me to get the desired output. I used the code suggested by Roberts but the data is not getting splitted in different columns of csv file and the output is on the same line in the html file.

Using the code:
$CSVContents | ConvertTo-HTML -Fragment | out-file -filepath $htmlFilePath -encoding ascii -append , I am getting the following html output. I really don't know how to get rid off this. Please provide me the complete code by modifying my existing code snippet.

Author Comment

ID: 35759254
Could you plese take a look on my problem and help me out?

Author Closing Comment

ID: 36116495
Not yet solved.

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Loops Section Overview
Screencast - Getting to Know the Pipeline

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question