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

Posted on 2011-04-30
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
    LVL 2

    Accepted Solution

    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

    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.
    LVL 2

    Assisted Solution

    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.
    LVL 2

    Expert Comment

    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


    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

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

    Author Closing Comment

    Not yet solved.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    #Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now