JDGEEK JDGEEK - 4 months ago 10
HTML Question

Joining two HTML scripts together

almost identical HTML scripts, each generated by a Powershell script and creates a .html output to a local drive. The output is a table of results following some queries on servers.

Each HTML output file opens up an is formatted as expected, However, I wish to combine the two output files into one script, which will feed into an email as a single HTML message. Please excuse the crude formatting - I have removed the styling from the script for simplicity.

Here is Script 1, which will be known in Powershell as $Table1:

<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>App Report</title>
</head>

<body>
<font face='calibri' color='#003399' size='4'><strong>App Server Report</strong></font>
</td>
</tr>
</table>

<table width='auto'><tbody>
<td width='auto' bgcolor='#d98880'' align='center'>Server</td>
<td width='auto' bgcolor='#a9dfbf'' align='center'>Service</td>
</tr>
<tr>
<td width='auto'>Server1</td>
<td width='auto' align='center'>Running</td>
</tr>
</tr>


Here is the output for Script1, known as $Table2:

Script1

...and here is Script 2:

<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
<title>Web Report</title>

</head>

<body>
<font face='calibri' color='#003399' size='4'><strong>Web Server Report</strong></font>
</td>
</tr>
</table>

<table width='auto'><tbody>
<td width='auto' bgcolor='#d98880'' align='center'>Server</td>
<td width='auto' bgcolor='#aed6f1'' align='center'>Apache Service</td>
<td width='auto' bgcolor='#aed6f1'' align='center'>WWW Service</td>
<td width='auto' bgcolor='#aed6f1'' align='center'>WAS Service</td>
</tr>
<tr>
<td width='auto'>SERVER2</td>
<td width='auto' align='center'>Running</td>
<td width='auto' align='center'>Running</td>
<td width='auto' align='center'>Running</td>
</tr>
</tr>


And here is the formatted output:

Script2

So now in my PS script I have put both of these into an HTML variable:

$HTMLmessage = @"
$Table1
$Table2
"@


But the Title for $Table2 is nested into the final td of the previous table. I know there must be a proper way of doing this - I'm not HTML literate, but any help would be appreciated.

Thanks

Answer

I see mainly 2 issues:

first: you can't have 2 <html> and <body> tags, so basically you have to cut out from $table2

second: there are many unopend or not closed tags.

Output of first script has to be:

<html> 
  <head> 
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
     <title>App Report</title> 
  </head> 

  <body> 
     <font face='calibri' color='#003399' size='4'><strong>App Server Report</strong></font> 


 <table width='auto'>
<tr> 
 <td width='auto' bgcolor='#d98880'' align='center'>Server</td>
 <td width='auto' bgcolor='#a9dfbf'' align='center'>Service</td> 
 </tr> 
      <tr> 
      <td width='auto'>Server1</td> 
      <td width='auto' align='center'>Running</td>
      </tr> 
 </tr> 
</table>

and the second one:

     <font face='calibri' color='#003399' size='4'><strong>Web Server Report</strong></font> 


     <table width='auto'><tr> 
     <td width='auto' bgcolor='#d98880'' align='center'>Server</td>
     <td width='auto' bgcolor='#aed6f1'' align='center'>Apache Service</td>  
     <td width='auto' bgcolor='#aed6f1'' align='center'>WWW Service</td>
     <td width='auto' bgcolor='#aed6f1'' align='center'>WAS Service</td>
     </tr>
     <tr> 
          <td width='auto'>SERVER2</td>  
          <td width='auto' align='center'>Running</td>
          <td width='auto' align='center'>Running</td>
          <td width='auto' align='center'>Running</td>
          </tr>
    </tr>   
</table>
</body>
</html>

(omit /body and /html if you'll want to add some other outputs)

Now it's your choice how to parse the output to operate the substutions or fix the script to obtain a well format HTML

Comments