Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PowerShell to crete HTML report

Posted on 2012-12-23
16
Medium Priority
?
757 Views
Last Modified: 2012-12-23
I am using the attached PowerShell scripts (XeAapp_Check.ps1, Ctx_functions.ps1) to export the XenApp 4.5 Zone details to HTML file as a report. On executing the script for the first time I am getting the desired result but unfortunately everytime I execute the script, the zone details gets appended to that report.

Here is my server details:

Farm Name: MyFarm

Server Name              zone Name
==========               ==========
XEN-1                           192.168.1.0
XEN-2                           TEST ZONE

Please assist me to get the correct result so that I can get the desired output by correctly modifying that script.
Ctx-Functions.txt
XenApp-Check.txt
XenApp-Check--Farm-Name--MyFarm-.mht
0
Comment
Question by:hchabria
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 38716716
the problem is that its appended to the html result instead of generating fresh one?
can u describe expected result?
0
 

Author Comment

by:hchabria
ID: 38716718
Yes, that is the exact problem. Can you please guide me to rectify this?
0
 

Author Comment

by:hchabria
ID: 38716721
Please find the attached expected result.
XenApp-Check--Farm-Name--MyFarm-.mht
0
Protect Your Retail Business and Reputation

Wi-Fi access doesn't just impact your business & customer experience, it can also affect your security.  Join us for an informative webinar to learn more about the top threats and trends impacting retail today, and the key solutions to protecting retail networks and reputations.

 
LVL 42

Expert Comment

by:sedgwick
ID: 38716748
in XenApp-Check.txt script just before you call out-file to save as .htm (scroll all the way down the script), you wanna delete them if already exists:

if(Test-Path  $FileXenApp_Check){
remove-item $FileXenApp_Check
}

if(Test-Path  $FileXenApp_CheckBackup){
remove-item  $FileXenApp_CheckBackup
	
}

$XenAppReport | out-file -encoding ASCII -filepath $FileXenApp_Check
$XenAppReport | out-file -encoding ASCII -filepath $FileXenApp_CheckBackup
	
echo "DONE"

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38716829
i saw that you hard coded:
$Check_OutputEnteteZone = "TRUE"

when u generate the html, you iterate the zones:
If ($Check_OutputEnteteZone -eq "TRUE")
{
Foreach ($Zones in $Zones) {

so the if statement is redundant (cause its always true).
0
 

Author Comment

by:hchabria
ID: 38716838
I've added the code you provided but still having the same result (please see the attached file). The report gets deleted but when recreated, the restult gets appended in the report.

I am not that much expert on PowerShell. Can you please guide me what should I do in case if I set $Check_OutputEnteteZone = "TRUE".

It would be very helpful of me if you could provide me the rectified code.
XenApp-Check--Farm-Name--MyFarm-.mht
0
 

Author Comment

by:hchabria
ID: 38716843
Event I've deleted the "If ($Check_OutputEnteteZone -eq "TRUE")" condition and then executed the script, but getting same result.

#Farm Name
$XenAppReport = Get-CustomHTML "Farm Name : $Farm"
$XenAppReport += Get-CustomHeaderClose

#Write-CustomOut "..Adding Zones Details Info to the report"
	Foreach ($Zones in $Zones) {
	$OutputEnteteZone2 += @($Zones | Select @{N="Zone Name";E={if($Zones.ZoneName -eq $Null){"Error"}else{$Zones.ZoneName}}}, @{N="Zone Data Collector";E={if($Zones.DataCollector -eq $Null){"Error"}else{$Zones.DataCollector}}}) }
	$XenAppReport += Get-CustomHeader ("Zone(s) Details : "+($Zones_Count))
	$XenAppReport += Get-HTMLTable $OutputEnteteZone2
	$XenAppReport += Get-CustomHeaderClose
	

$Date = Get-Date -Format "yyyyMMddHH"
$FileXenApp_Check = $Path + $FileName + ".htm"
$FileXenApp_CheckBackup = $PathBackup + $FileName + "_" + $date + ".htm"


if(Test-Path  $FileXenApp_Check){
remove-item $FileXenApp_Check
}

if(Test-Path  $FileXenApp_CheckBackup){
remove-item  $FileXenApp_CheckBackup
	
}

$XenAppReport | out-file -encoding ASCII -filepath $FileXenApp_Check
$XenAppReport | out-file -encoding ASCII -filepath $FileXenApp_CheckBackup
	
echo "DONE"

Open in new window

0
 

Author Comment

by:hchabria
ID: 38716848
What I have seen that, if I change the following variable name everytime then, I am getting the desired result.

$OutputEnteteZone

Also, I there is any way to delete the value of that variable then I think the result will come but I don't have any clue about how to do this.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38716850
change this:
If ($Check_OutputEnteteZone -eq "TRUE")
{
	Foreach ($Zones in $Zones) {
	$OutputEnteteZone1 += @($Zones | Select @{N="Zone Name";E={if($Zones.ZoneName -eq $Null){"Error"}else{$Zones.ZoneName}}}, @{N="Zone Data Collector";E={if($Zones.DataCollector -eq $Null){"Error"}else{$Zones.DataCollector}}}) }
	$XenAppReport += Get-CustomHeader ("Zone(s) Details : "+($Zones_Count))
	$XenAppReport += Get-HTMLTable $OutputEnteteZone1
	$XenAppReport += Get-CustomHeaderClose
}

Open in new window


to this:
	$OutputEnteteZone1 += @($Zones | Select @{N="Zone Name";E={if($Zones.ZoneName -eq $Null){"Error"}else{$Zones.ZoneName}}}, @{N="Zone Data Collector";E={if($Zones.DataCollector -eq $Null){"Error"}else{$Zones.DataCollector}}}) 
	$XenAppReport += Get-CustomHeader ("Zone(s) Details : "+($Zones_Count))
	$XenAppReport += Get-HTMLTable $OutputEnteteZone1
	$XenAppReport += Get-CustomHeaderClose

Open in new window


--> remove if stetment and foreach stetment.
the if is redundant and the foreach already takes place when you call:
$OutputEnteteZone1 += @($Zones | ....
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38716855
btw, can u debug your script?
0
 

Author Comment

by:hchabria
ID: 38716861
Please find below the code as you instructed and the attached result. The result is getting appended everytime and the ouput is producing an error as $Zones.ZoneName value is producing NULL value.

$XenAppReport = Get-CustomHTML "Farm Name : $Farm"
$XenAppReport += Get-CustomHeaderClose

$OutputEnteteZone1 += @($Zones | Select @{N="Zone Name";E={if($Zones.ZoneName -eq $Null){"Error"}else{$Zones.ZoneName}}}, @{N="Zone Data Collector";E={if($Zones.DataCollector -eq $Null){"Error"}else{$Zones.DataCollector}}}) 
$XenAppReport += Get-CustomHeader ("Zone(s) Details : "+($Zones_Count))
$XenAppReport += Get-HTMLTable $OutputEnteteZone1
$XenAppReport += Get-CustomHeaderClose

$Date = Get-Date -Format "yyyyMMddHH"
$FileXenApp_Check = $Path + $FileName + ".htm"
$FileXenApp_CheckBackup = $PathBackup + $FileName + "_" + $date + ".htm"

if(Test-Path  $FileXenApp_Check){
remove-item $FileXenApp_Check
}
if(Test-Path  $FileXenApp_CheckBackup){
remove-item  $FileXenApp_CheckBackup
}

$XenAppReport | out-file -encoding ASCII -filepath $FileXenApp_Check
$XenAppReport | out-file -encoding ASCII -filepath $FileXenApp_CheckBackup
	
echo "DONE"

Open in new window

Report.PNG
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38716866
the problem is not appending the file but the $zones creation.
there's a function called GET-XAZone i assume which returns aggregated $Zones.
i couldn't;t find source of this function in the files you've attached.
please check $Zones.Count when code is back from GET-XAZone.
i guess that from second run you get aggregated result.
but again do not have the source of GET-XAZone.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 38716867
btw, you can remove the test-path code i've suggested before cause its not the issue.
0
 

Author Comment

by:hchabria
ID: 38716868
I posted the above result after debugging my script only.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 38716869
Did you try setting $OutputEnteteZone1 to $null
$OutputEnteteZone1 = $null
If ($Check_OutputEnteteZone -eq "TRUE")
{
	
	Foreach ($Zones in $Zones) {
	$OutputEnteteZone1 += @($Zones | Select @{N="Zone Name";E={if($Zones.ZoneName -eq $Null){"Error"}else{$Zones.ZoneName}}}, @{N="Zone Data Collector";E={if($Zones.DataCollector -eq $Null){"Error"}else{$Zones.DataCollector}}}) }
	$XenAppReport += Get-CustomHeader ("Zone(s) Details : "+($Zones_Count))
	$XenAppReport += Get-HTMLTable $OutputEnteteZone1
	$XenAppReport += Get-CustomHeaderClose
	
}

Open in new window

0
 

Author Comment

by:hchabria
ID: 38716874
Excellent Subsun. It's working perfectly now after setting $OutputEnteteZone1 to $null.

Thank you so much.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

671 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