<\/div>\n<\/aside>\n\n
Apparently, I can see into the future, I’m not sure how this post arrived before yours (which I replied to!). But…ok…<\/p>","upvoteCount":1,"datePublished":"2014-06-12T12:47:44.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/8","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}},{"@type":"Answer","text":"
Yes browser is IE and Outlook is email client, here’s the source code from Outlook:<\/p>\n
<html><head>\n<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>\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2014-06-12T12:48:10.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/9","author":{"@type":"Person","name":"craighamon2700","url":"https://community.spiceworks.com/u/craighamon2700"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Rob Dunn:<\/div>\n
\nLooks like there’s a missing at the end.<\/p>\n
This site is super-handy, btw!<\/p>\n
Free Online HTML Validator - FreeFormatter.com<\/a><\/p>\nApparently, I can see into the future, I’m not sure how this post arrived before yours (which I replied to!). But…ok…<\/p>\n<\/blockquote>\n<\/aside>\n
Yep, that’s going in the toolbox!!<\/p>\n
Charass, Looking through your HTML definitely missing the /table tag… I bet you’re missing all of them.<\/p>","upvoteCount":0,"datePublished":"2014-06-12T12:51:38.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/10","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"
I deleted it and re posted as it didn’t look right. You’re right according to that validator I’m missing this:<\/p>\n Isn't Allowed In Elements (At line 2, column 15114)\n
Missing <\/p>
<\/tbody><\/table> Before (At line 2, column 15749)<\/p>\n
Along with a bunch of Attribute “width” Has Invalid Value warnings<\/p>\n
So I guess the question is how to fix this in the original script.<\/p>","upvoteCount":0,"datePublished":"2014-06-12T12:57:20.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/11","author":{"@type":"Person","name":"craighamon2700","url":"https://community.spiceworks.com/u/craighamon2700"}},{"@type":"Answer","text":"
Well, to simplify this code, can we do this?<\/p>\n
Function writeDiskInfo \n{ \nparam($fileName,$devId,$volName,$frSpace,$totSpace) \n$totSpace=[math]::Round(($totSpace/1073741824),2) \n$frSpace=[Math]::Round(($frSpace/1073741824),2) \n$usedSpace = $totSpace - $frspace \n$usedSpace=[Math]::Round($usedSpace,2) \n$freePercent = ($frspace/$totSpace)*100 \n$freePercent = [Math]::Round($freePercent,0)\n if ($freePercent -gt $warning) \n { \n $bgcolor = \"\"\n } \n elseif ($freePercent -le $critical) \n { \n $bgcolor = \"#FF0000\"\n } \n else \n { \n $bgcolor = \"#FBB917\"\n } \n Add-Content $fileName \"<tr>\" \n Add-Content $fileName \"<td>$devid</td>\" \n Add-Content $fileName \"<td>$volName</td>\" \n Add-Content $fileName \"<td>$totSpace</td>\" \n Add-Content $fileName \"<td>$usedSpace</td>\" \n Add-Content $fileName \"<td>$frSpace</td>\" \n Add-Content $fileName \"<td bgcolor='$bgcolor' align=center>$freePercent</td>\" \n # #FBB917 \n Add-Content $fileName \"</tr>\" \n\n} \n<\/code><\/pre>\nJust make sure that before and after you call this function, open and close out your table tags. I don’t think the table in the tbody will affect anything too bad (it’s bad form, I suppose, but it should still render).<\/p>\n
Where does the table code begin in your parent script? How is it called?<\/p>","upvoteCount":1,"datePublished":"2014-06-12T13:11:04.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/12","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}},{"@type":"Answer","text":"
I’m not really a scripting expert, shall I just post the entire script (didn’t want to cause I know it’s bad form)?<\/p>","upvoteCount":0,"datePublished":"2014-06-12T13:25:59.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/13","author":{"@type":"Person","name":"craighamon2700","url":"https://community.spiceworks.com/u/craighamon2700"}},{"@type":"Answer","text":"
If it’s too long, you can attach it as a file - otherwise, go for it!<\/p>","upvoteCount":0,"datePublished":"2014-06-12T13:27:52.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/14","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}},{"@type":"Answer","text":"
Here you go:<\/p>\n
# First lets create a text file, where we will later save the freedisk space info \n$freeSpaceFileName = \"FreeSpace.htm\" \n$serverlist = \"ServerList.txt\" \n$warning = 25 \n$critical = 10 \nNew-Item -ItemType file $freeSpaceFileName -Force \n# Getting the freespace info using WMI \n#Get-WmiObject win32_logicaldisk | Where-Object {$_.drivetype -eq 3} | format-table DeviceID, \n\nVolumeName,status,Size,FreeSpace | Out-File FreeSpace.txt \n# Function to write the HTML Header to the file \nFunction writeHtmlHeader \n{ \nparam($fileName) \n$date = ( get-date ).ToString('yyyy/MM/dd')\nadd-content $fileName \"<table>\" \nAdd-Content $fileName \"<html>\" \nAdd-Content $fileName \"<head>\" \nAdd-Content $fileName \"<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\" \nAdd-Content $fileName '<title>Disk Space Report</title>' \nadd-content $fileName '<STYLE TYPE=\"text/css\">' \nadd-content $fileName \"<!--\" \nadd-content $fileName \"td {\" \nadd-content $fileName \"font-family: Tahoma;\" \nadd-content $fileName \"font-size: 11px;\" \nadd-content $fileName \"border-top: 1px solid #999999;\" \nadd-content $fileName \"border-right: 1px solid #999999;\" \nadd-content $fileName \"border-bottom: 1px solid #999999;\" \nadd-content $fileName \"border-left: 1px solid #999999;\" \nadd-content $fileName \"padding-top: 0px;\" \nadd-content $fileName \"padding-right: 0px;\" \nadd-content $fileName \"padding-bottom: 0px;\" \nadd-content $fileName \"padding-left: 0px;\" \nadd-content $fileName \"}\" \nadd-content $fileName \"body {\" \nadd-content $fileName \"margin-left: 5px;\" \nadd-content $fileName \"margin-top: 5px;\" \nadd-content $fileName \"margin-right: 0px;\" \nadd-content $fileName \"margin-bottom: 10px;\" \nadd-content $fileName \"\" \nadd-content $fileName \"table {\" \nadd-content $fileName \"border: thin solid #000000;\" \nadd-content $fileName \"}\" \nadd-content $fileName \"-->\" \nadd-content $fileName \"</style>\" \nAdd-Content $fileName \"</head>\" \nAdd-Content $fileName \"<body>\" \nadd-content $fileName \"<table width='100%'>\" \nadd-content $fileName \"<tr bgcolor='#CCCCCC'>\" \nadd-content $fileName \"<td colspan='7' height='25' align='center'>\" \nadd-content $fileName \"<font face='tahoma' color='#003399' size='4'><strong>Disk Space Report - $date</strong></font>\" \nadd-content $fileName \"</td>\" \nadd-content $fileName \"</tr>\" \nadd-content $fileName \"</table>\" \n \n} \n \n# Function to write the HTML Header to the file \nFunction writeTableHeader \n{ \nparam($fileName) \n \nAdd-Content $fileName \"<tr bgcolor=#CCCCCC>\" \nAdd-Content $fileName \"<td width='10%' align='center'>Drive</td>\" \nAdd-Content $fileName \"<td width='50%' align='center'>Drive Label</td>\" \nAdd-Content $fileName \"<td width='10%' align='center'>Total Capacity(GB)</td>\" \nAdd-Content $fileName \"<td width='10%' align='center'>Used Capacity(GB)</td>\" \nAdd-Content $fileName \"<td width='10%' align='center'>Free Space(GB)</td>\" \nAdd-Content $fileName \"<td width='10%' align='center'>Freespace %</td>\" \nAdd-Content $fileName \"</tr>\" \n} \n \nFunction writeHtmlFooter \n{ \nparam($fileName) \n \nAdd-Content $fileName \"</body>\" \nAdd-Content $fileName \"</html>\" \n} \n \nFunction writeDiskInfo \n{ \nparam($fileName,$devId,$volName,$frSpace,$totSpace) \n$totSpace=[math]::Round(($totSpace/1073741824),2) \n$frSpace=[Math]::Round(($frSpace/1073741824),2) \n$usedSpace = $totSpace - $frspace \n$usedSpace=[Math]::Round($usedSpace,2) \n$freePercent = ($frspace/$totSpace)*100 \n$freePercent = [Math]::Round($freePercent,0)\n if ($freePercent -gt $warning) \n { \n $bgcolor = \"\"\n } \n elseif ($freePercent -le $critical) \n { \n $bgcolor = \"#FF0000\"\n } \n else \n { \n $bgcolor = \"#FBB917\"\n } \n Add-Content $fileName \"<tr>\" \n Add-Content $fileName \"<td>$devid</td>\" \n Add-Content $fileName \"<td>$volName</td>\" \n Add-Content $fileName \"<td>$totSpace</td>\" \n Add-Content $fileName \"<td>$usedSpace</td>\" \n Add-Content $fileName \"<td>$frSpace</td>\" \n Add-Content $fileName \"<td bgcolor='$bgcolor' align=center>$freePercent</td>\" \n # #FBB917 \n Add-Content $fileName \"</tr>\" \n\n}\n \nFunction sendEmail \n{ param($from,$to,$subject,$smtphost,$htmlFileName)\n#$Attachment = \"C:\\Scripts\\Drivespace\\Freespace.html\"\n$body = Get-Content $htmlFileName \n$smtp= New-Object System.Net.Mail.SmtpClient $smtphost \n$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body\n#$msg.Attachments.Add($Attachment) \n$msg.isBodyhtml = $true \n$smtp.send($msg) \n \n} \n \nwriteHtmlHeader $freeSpaceFileName \nforeach ($server in Get-Content $serverlist) \n{ \n Add-Content $freeSpaceFileName \"<table width='100%'><tbody>\" \n Add-Content $freeSpaceFileName \"<tr bgcolor='#CCCCCC'>\" \n Add-Content $freeSpaceFileName \"<td width='100%' align='center' colSpan=6><font face='tahoma' color='#003399' \n\nsize='2'><strong> $server </strong></font></td>\" \n Add-Content $freeSpaceFileName \"</tr>\" \n \n writeTableHeader $freeSpaceFileName \n \n $dp = Get-WmiObject win32_logicaldisk -ComputerName $server | Where-Object {$_.drivetype -eq 3} \n foreach ($item in $dp) \n { \n Write-Host $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size \n writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size \n \n } \n} \nwriteHtmlFooter $freeSpaceFileName \n$date = ( get-date ).ToString('yyyy/MM/dd') \nsendEmail [email protected] [email protected] \"Disk Space Report - $Date\" SMTPSERVER $freeSpaceFileName \n<\/code><\/pre>","upvoteCount":0,"datePublished":"2014-06-12T13:31:24.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/15","author":{"@type":"Person","name":"craighamon2700","url":"https://community.spiceworks.com/u/craighamon2700"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Rob Dunn:<\/div>\n
\nIf it’s too long, you can attach it as a file - otherwise, go for it!<\/p>\n<\/blockquote>\n<\/aside>\n
Yah, at this point I think we need to see the whole thing. Post away! <Preparing self for wall o’ code><\/p>","upvoteCount":0,"datePublished":"2014-06-12T13:31:43.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/16","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"
Here:<\/p>\n
Function writeHtmlFooter \n{ \nparam($fileName) \n\n#ADD THIS LINE\nAdd-Content $filename \"</table>\"\n#ADD ABOVE LINE\nAdd-Content $fileName \"</body>\" \nAdd-Content $fileName \"</html>\" \n} \n<\/code><\/pre>\nTry this?<\/p>","upvoteCount":0,"datePublished":"2014-06-12T13:40:19.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/17","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}},{"@type":"Answer","text":"
More than one table tho, so I think you have to add it just after the writeDiskInfo function (after the loop).<\/p>","upvoteCount":0,"datePublished":"2014-06-12T13:52:55.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/18","author":{"@type":"Person","name":"martin9700","url":"https://community.spiceworks.com/u/martin9700"}},{"@type":"Answer","text":"
Made change, same result.<\/p>","upvoteCount":0,"datePublished":"2014-06-12T13:53:49.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/19","author":{"@type":"Person","name":"craighamon2700","url":"https://community.spiceworks.com/u/craighamon2700"}},{"@type":"Answer","text":"
Looks like you need a tablefooter function:<\/p>\n
# Function to write the HTML Header to the file \nFunction writeTableFooter \n{ \nparam($fileName) \n \nAdd-Content $fileName \"</table>\" \n} \n<\/code><\/pre>\nThen<\/p>\n
writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size \nwriteTableFooter $freeSpaceFileName \n<\/code><\/pre>","upvoteCount":1,"datePublished":"2014-06-12T13:56:05.000Z","url":"https://community.spiceworks.com/t/powershell-drive-space-script/312063/20","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}}]}}
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:
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
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:
Rob-Dunn
(Rob Dunn)
June 12, 2014, 10:20am
6
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).
Rob-Dunn
(Rob Dunn)
June 12, 2014, 12:47pm
8
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>
Rob Dunn:
Looks like there’s a missing at the end.
This site is super-handy, btw!
Free Online HTML Validator - FreeFormatter.com
Apparently, I can see into the future, I’m not sure how this post arrived before yours (which I replied to!). But…ok…
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
Before (At line 2, column 15749)
Along with a bunch of Attribute “width” Has Invalid Value warnings
So I guess the question is how to fix this in the original script.
Rob-Dunn
(Rob Dunn)
June 12, 2014, 1:11pm
12
Well, to simplify this code, can we do this?
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)
{
$bgcolor = ""
}
elseif ($freePercent -le $critical)
{
$bgcolor = "#FF0000"
}
else
{
$bgcolor = "#FBB917"
}
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='$bgcolor' align=center>$freePercent</td>"
# #FBB917
Add-Content $fileName "</tr>"
}
Just make sure that before and after you call this function, open and close out your table tags. I don’t think the table in the tbody will affect anything too bad (it’s bad form, I suppose, but it should still render).
Where does the table code begin in your parent script? How is it called?
1 Spice up
I’m not really a scripting expert, shall I just post the entire script (didn’t want to cause I know it’s bad form)?
Rob-Dunn
(Rob Dunn)
June 12, 2014, 1:27pm
14
If it’s too long, you can attach it as a file - otherwise, go for it!
Here you go:
# First lets create a text file, where we will later save the freedisk space info
$freeSpaceFileName = "FreeSpace.htm"
$serverlist = "ServerList.txt"
$warning = 25
$critical = 10
New-Item -ItemType file $freeSpaceFileName -Force
# Getting the freespace info using WMI
#Get-WmiObject win32_logicaldisk | Where-Object {$_.drivetype -eq 3} | format-table DeviceID,
VolumeName,status,Size,FreeSpace | Out-File FreeSpace.txt
# Function to write the HTML Header to the file
Function writeHtmlHeader
{
param($fileName)
$date = ( get-date ).ToString('yyyy/MM/dd')
add-content $fileName "<table>"
Add-Content $fileName "<html>"
Add-Content $fileName "<head>"
Add-Content $fileName "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"
Add-Content $fileName '<title>Disk Space Report</title>'
add-content $fileName '<STYLE TYPE="text/css">'
add-content $fileName "<!--"
add-content $fileName "td {"
add-content $fileName "font-family: Tahoma;"
add-content $fileName "font-size: 11px;"
add-content $fileName "border-top: 1px solid #999999;"
add-content $fileName "border-right: 1px solid #999999;"
add-content $fileName "border-bottom: 1px solid #999999;"
add-content $fileName "border-left: 1px solid #999999;"
add-content $fileName "padding-top: 0px;"
add-content $fileName "padding-right: 0px;"
add-content $fileName "padding-bottom: 0px;"
add-content $fileName "padding-left: 0px;"
add-content $fileName "}"
add-content $fileName "body {"
add-content $fileName "margin-left: 5px;"
add-content $fileName "margin-top: 5px;"
add-content $fileName "margin-right: 0px;"
add-content $fileName "margin-bottom: 10px;"
add-content $fileName ""
add-content $fileName "table {"
add-content $fileName "border: thin solid #000000;"
add-content $fileName "}"
add-content $fileName "-->"
add-content $fileName "</style>"
Add-Content $fileName "</head>"
Add-Content $fileName "<body>"
add-content $fileName "<table width='100%'>"
add-content $fileName "<tr bgcolor='#CCCCCC'>"
add-content $fileName "<td colspan='7' height='25' align='center'>"
add-content $fileName "<font face='tahoma' color='#003399' size='4'><strong>Disk Space Report - $date</strong></font>"
add-content $fileName "</td>"
add-content $fileName "</tr>"
add-content $fileName "</table>"
}
# Function to write the HTML Header to the file
Function writeTableHeader
{
param($fileName)
Add-Content $fileName "<tr bgcolor=#CCCCCC>"
Add-Content $fileName "<td width='10%' align='center'>Drive</td>"
Add-Content $fileName "<td width='50%' align='center'>Drive Label</td>"
Add-Content $fileName "<td width='10%' align='center'>Total Capacity(GB)</td>"
Add-Content $fileName "<td width='10%' align='center'>Used Capacity(GB)</td>"
Add-Content $fileName "<td width='10%' align='center'>Free Space(GB)</td>"
Add-Content $fileName "<td width='10%' align='center'>Freespace %</td>"
Add-Content $fileName "</tr>"
}
Function writeHtmlFooter
{
param($fileName)
Add-Content $fileName "</body>"
Add-Content $fileName "</html>"
}
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)
{
$bgcolor = ""
}
elseif ($freePercent -le $critical)
{
$bgcolor = "#FF0000"
}
else
{
$bgcolor = "#FBB917"
}
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='$bgcolor' align=center>$freePercent</td>"
# #FBB917
Add-Content $fileName "</tr>"
}
Function sendEmail
{ param($from,$to,$subject,$smtphost,$htmlFileName)
#$Attachment = "C:\Scripts\Drivespace\Freespace.html"
$body = Get-Content $htmlFileName
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
#$msg.Attachments.Add($Attachment)
$msg.isBodyhtml = $true
$smtp.send($msg)
}
writeHtmlHeader $freeSpaceFileName
foreach ($server in Get-Content $serverlist)
{
Add-Content $freeSpaceFileName "<table width='100%'><tbody>"
Add-Content $freeSpaceFileName "<tr bgcolor='#CCCCCC'>"
Add-Content $freeSpaceFileName "<td width='100%' align='center' colSpan=6><font face='tahoma' color='#003399'
size='2'><strong> $server </strong></font></td>"
Add-Content $freeSpaceFileName "</tr>"
writeTableHeader $freeSpaceFileName
$dp = Get-WmiObject win32_logicaldisk -ComputerName $server | Where-Object {$_.drivetype -eq 3}
foreach ($item in $dp)
{
Write-Host $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
}
}
writeHtmlFooter $freeSpaceFileName
$date = ( get-date ).ToString('yyyy/MM/dd')
sendEmail DriveSpaceReport@someone.com Me@somewhere.com "Disk Space Report - $Date" SMTPSERVER $freeSpaceFileName
Yah, at this point I think we need to see the whole thing. Post away! <Preparing self for wall o’ code>
Rob-Dunn
(Rob Dunn)
June 12, 2014, 1:40pm
17
Here:
Function writeHtmlFooter
{
param($fileName)
#ADD THIS LINE
Add-Content $filename "</table>"
#ADD ABOVE LINE
Add-Content $fileName "</body>"
Add-Content $fileName "</html>"
}
Try this?
More than one table tho, so I think you have to add it just after the writeDiskInfo function (after the loop).
Made change, same result.
Rob-Dunn
(Rob Dunn)
June 12, 2014, 1:56pm
20
Looks like you need a tablefooter function:
# Function to write the HTML Header to the file
Function writeTableFooter
{
param($fileName)
Add-Content $fileName "</table>"
}
Then
writeDiskInfo $freeSpaceFileName $item.DeviceID $item.VolumeName $item.FreeSpace $item.Size
writeTableFooter $freeSpaceFileName
1 Spice up