• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2458
  • Last Modified:

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

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

$log_file="D:\LoadEvaluator.log"
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.

PROBLEM
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

 LoadEvaluator.log
 LoadEvaluator.csv
 LoadEvaluatorReport.htm
0
hchabria
Asked:
hchabria
  • 4
  • 2
2 Solutions
 
robertkennedyCommented:
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.
0
 
hchabriaAuthor Commented:
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.
0
 
robertkennedyCommented:
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.
0
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

 
AussieClintCommented:
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.
0
 
hchabriaAuthor Commented:
Hi,

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.
 LoadEvaluatorReport.html
0
 
hchabriaAuthor Commented:
Could you plese take a look on my problem and help me out?
0
 
hchabriaAuthor Commented:
Not yet solved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now