Hi Guys,

I have a powershell script that gets server drive space pipes it into an html file which gets inserted into an email using the Get-Content command. The problem is that whilst the html file looks really good when that gets inserted into an email all the tables overlap. i think the problem is with this part of the script:

Function writeDiskInfo 
{ 
param($fileName,$devId,$volName,$frSpace,$totSpace) 
$totSpace=[math]::Round(($totSpace/1073741824),2) 
$frSpace=[Math]::Round(($frSpace/1073741824),2) 
$usedSpace = $totSpace - $frspace 
$usedSpace=[Math]::Round($usedSpace,2) 
$freePercent = ($frspace/$totSpace)*100 
$freePercent = [Math]::Round($freePercent,0)
 if ($freePercent -gt $warning) 
 { 
 Add-Content $fileName "<tr>" 
 Add-Content $fileName "<td>$devid</td>" 
 Add-Content $fileName "<td>$volName</td>" 
 Add-Content $fileName "<td>$totSpace</td>" 
 Add-Content $fileName "<td>$usedSpace</td>" 
 Add-Content $fileName "<td>$frSpace</td>" 
 Add-Content $fileName "<td>$freePercent</td>" 
 Add-Content $fileName "</tr>" 
 } 
 elseif ($freePercent -le $critical) 
 { 
 Add-Content $fileName "<tr>" 
 Add-Content $fileName "<td>$devid</td>" 
 Add-Content $fileName "<td>$volName</td>" 
 Add-Content $fileName "<td>$totSpace</td>" 
 Add-Content $fileName "<td>$usedSpace</td>" 
 Add-Content $fileName "<td>$frSpace</td>" 
 Add-Content $fileName "<td bgcolor='#FF0000' align=center>$freePercent</td>" 
 #<td bgcolor='#FF0000' align=center> 
 Add-Content $fileName "</tr>" 
 } 
 else 
 { 
 Add-Content $fileName "<tr>" 
 Add-Content $fileName "<td>$devid</td>" 
 Add-Content $fileName "<td>$volName</td>" 
 Add-Content $fileName "<td>$totSpace</td>" 
 Add-Content $fileName "<td>$usedSpace</td>" 
 Add-Content $fileName "<td>$frSpace</td>" 
 Add-Content $fileName "<td bgcolor='#FBB917' align=center>$freePercent</td>" 
 # #FBB917 
 Add-Content $fileName "</tr>" 
 } 
} 

I tried inserting Add-Content $fileName “” before the last parenthesis but that results in this:Capture.JPG
Thanks

Craig

7 Spice ups

Looks like your function is only adding one line to your table at a time, so you wouldn’t want your /table tag to come from the function (otherwise you get the above). You must have a loop that’s feeding the function? I would put the Add-Content $FileName “” after that loop when you’re finishing up the HTML for sending.

Also, just for the sake of efficiency, in your function, you write all those lines of text:

 Add-Content $fileName "<tr>" 
 Add-Content $fileName "<td>$devid</td>" 
 Add-Content $fileName "<td>$volName</td>" 
 Add-Content $fileName "<td>$totSpace</td>" 
 Add-Content $fileName "<td>$usedSpace</td>" 
 Add-Content $fileName "<td>$frSpace</td>" 

Exactly the same each time. So just write them out before the IF statement. Then do your if but only write out the one line:

if ($freePercent -gt $warning) 
 { 
 Add-Content $fileName "<td>$freePercent</td>" 
 } 
 elseif ($freePercent -le $critical) 
 {  
 Add-Content $fileName "<td bgcolor='#FF0000' align=center>$freePercent</td>" 
 #<td bgcolor='#FF0000' align=center> 
 } 
 else 
 { 
 Add-Content $fileName "<td bgcolor='#FBB917' align=center>$freePercent</td>"
 }

And then write out the last line:

 Add-Content $fileName "</tr>" 
}

Just looks cleaner :slight_smile:

Also might want to take a look at:

http://community.spiceworks.com/scripts/show/1641-simple-server-status-report

I’ve made the changes you suggested but I still have the same problem. The html file looks just fine but when it’s inserted into an email it looks like this:

Thanks

Craig

So when you open the HTML file in a browser it looks ok?

Exactly, it looks like this when opened in a browser:

Can you ‘view source’ and post here (preferably from Outlook)?

Yah, I don’t know what else it would be.

Are you using IE as the browser and Outlook as the email client? All I can figure is it’s some incompatibility there (thank you IE).

Looks like there’s a missing at the end.

This site is super-handy, btw!

Apparently, I can see into the future, I’m not sure how this post arrived before yours (which I replied to!). But…ok…

1 Spice up

Yes browser is IE and Outlook is email client, here’s the source code from Outlook:

<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"> <title>Disk Space Report</title> <style type="text/css"> <!-- td { font-family: Tahoma; font-size: 11px; border-top: 1px solid #999999; border-right: 1px solid #999999; border-bottom: 1px solid #999999; border-left: 1px solid #999999; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; } body { margin-left: 5px; margin-top: 5px; margin-right: 0px; margin-bottom: 10px;  table { border: thin solid #000000; } --> </style> </head> <body> <table width="100%"> <tr bgcolor="#CCCCCC"> <td colspan="7" height="25" align="center"> <font face="tahoma" color="#003399" size="4"><strong>Gentoo Fund Services Disk Space Report - 2014/06/12</strong></font> </td> </tr> </table> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> GENGGAPP01 </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>48.22</td> <td>51.68</td> <td>52</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>34.91</td> <td>64.99</td> <td>65</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>178.46</td> <td>133.16</td> <td>45.3</td> <td bgcolor="#FBB917" align="center">25</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>28.32</td> <td>71.58</td> <td>72</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>141.25</td> <td>53.19</td> <td>88.06</td> <td>62</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>418.65</td> <td>0.14</td> <td>418.51</td> <td>100</td> </tr> <tr> <td>E:</td> <td>AppAssure</td> <td>7450.87</td> <td>4584.74</td> <td>2866.13</td> <td>38</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>77.24</td> <td>22.66</td> <td bgcolor="#FBB917" align="center">23</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>1024</td> <td>564.31</td> <td>459.69</td> <td>45</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>52.02</td> <td>47.88</td> <td>48</td> </tr> <tr> <td>D:</td> <td>Exchange</td> <td>310</td> <td>198.4</td> <td>111.6</td> <td>36</td> </tr> <tr> <td>E:</td> <td>Exchange</td> <td>250</td> <td>103.64</td> <td>146.36</td> <td>59</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>32.99</td> <td>66.91</td> <td>67</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>30.95</td> <td>68.95</td> <td>69</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>350</td> <td>300.77</td> <td>49.23</td> <td bgcolor="#FBB917" align="center">14</td> </tr> <tr> <td>E:</td> <td>Shadow Copy</td> <td>250</td> <td>61.5</td> <td>188.5</td> <td>75</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>39.84</td> <td>60.06</td> <td>60</td> </tr> <tr> <td>D:</td> <td>SQL</td> <td>250</td> <td>185.46</td> <td>64.54</td> <td>26</td> </tr> <tr> <td>E:</td> <td>Backup</td> <td>300</td> <td>172.74</td> <td>127.26</td> <td>42</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>82.61</td> <td>17.29</td> <td bgcolor="#FBB917" align="center">17</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>178.46</td> <td>100.58</td> <td>77.88</td> <td>44</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>83.16</td> <td>16.74</td> <td bgcolor="#FBB917" align="center">17</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>178.46</td> <td>108.14</td> <td>70.32</td> <td>39</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>79.86</td> <td>20.04</td> <td bgcolor="#FBB917" align="center">20</td> </tr> <tr> <td>D:</td> <td>Data</td> <td>178.46</td> <td>110.63</td> <td>67.83</td> <td>38</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>126.9</td> <td>28.1</td> <td>98.8</td> <td>78</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>58.72</td> <td>41.18</td> <td>41</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>278.37</td> <td>78.59</td> <td>199.78</td> <td>72</td> </tr> <tr> <td>D:</td> <td>Hyper-V</td> <td>1860.78</td> <td>785.32</td> <td>1075.46</td> <td>58</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>278.37</td> <td>58.22</td> <td>220.15</td> <td>79</td> </tr> <tr> <td>D:</td> <td>Hyper-V</td> <td>1673.58</td> <td>1216.61</td> <td>456.97</td> <td>27</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>141.5</td> <td>101.91</td> <td>39.59</td> <td>28</td> </tr> <tr> <td>D:</td> <td>Hyper-V</td> <td>2233.5</td> <td>843.56</td> <td>1389.94</td> <td>62</td> </tr> <tr> <td>E:</td> <td>AppAssure</td> <td>5587.87</td> <td>4584.64</td> <td>1003.23</td> <td bgcolor="#FBB917" align="center">18</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>141.25</td> <td>25.85</td> <td>115.4</td> <td>82</td> </tr> <tr> <td>D:</td> <td>Hyper-V</td> <td>3350.31</td> <td>1194.3</td> <td>2156.01</td> <td>64</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>141.25</td> <td>24.44</td> <td>116.81</td> <td>83</td> </tr> <tr> <td>D:</td> <td>Hyper-V</td> <td>3350.31</td> <td>1127.58</td> <td>2222.73</td> <td>66</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>226.15</td> <td>23.65</td> <td>202.5</td> <td>90</td> </tr> <tr> <td>D:</td> <td>Hyper-V</td> <td>2233.5</td> <td>1416.62</td> <td>816.88</td> <td>37</td> </tr> <table width="100%"><tbody> <tr bgcolor="#CCCCCC"> <td width="100%" align="center" colspan="6"><font face="tahoma" color="#003399" size="2"><strong> SERVER </strong></font></td> </tr> <tr bgcolor="#CCCCCC"> <td width="10%" align="center">Drive</td> <td width="50%" align="center">Drive Label</td> <td width="10%" align="center">Total Capacity(GB)</td> <td width="10%" align="center">Used Capacity(GB)</td> <td width="10%" align="center">Free Space(GB)</td> <td width="10%" align="center">Freespace %</td> </tr> <tr> <td>C:</td> <td>System</td> <td>99.9</td> <td>79.76</td> <td>20.14</td> <td bgcolor="#FBB917" align="center">20</td> </tr> </body> </html>

Yep, that’s going in the toolbox!!

Charass, Looking through your HTML definitely missing the /table tag… I bet you’re missing all of them.

I deleted it and re posted as it didn’t look right. You’re right according to that validator I’m missing this:

Isn't Allowed In Elements (At line 2, column 15114)

Missing