C Drive Free Space To HTML File
May 27, 2022
$html = @' <!DOCTYPE html PUBLIC> <html> <head> <style>BODY{{background-color:white;}}TABLE{{border-width: 2px;border-style: solid;border-color: black;border-collapse: separate;width:800px}}TH{{border-width: 1px;padding: 0px;border-style: solid;border -color: black;background-color:lightblue}}TD{{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:White}}</style> </head><body> <table> <colgroup><col/><col/><col/><col/><col/></colgroup> <tr><th>Computer</th><th>Driveletter</th><th>GBfreespace</th><th>Capacity</th><th>Percentage</th></tr> {0} </table> </body></html> '@ $trTemplate ='<tr><td>{0}</td><td>{1}</td><td>{2:N2}</td><td>{3:N2}</td><td {4}>{5:N2}%</td></tr>' $redStyle = 'style="background-color:Red"' $tr = @() $servers = GC C:\TEMP\list.txt #remove where { $_.drivetype -eq '3'} to search ALL Drives Foreach ($s in $servers) { Get-WmiObject -Class win32_volume -cn $s | where { $_.driveletter -eq 'C:'} | Where Capacity | ForEach-Object { $freespaceInPercent = ($_.freespace/$_.capacity*100) $red = '' if ($freespaceInPercent -lt [double]15) { $red = $redStyle } $tr += ($trTemplate -f $s, $_.driveletter, ($_.freespace/1GB), ($_.capacity/1GB), $red, $freespaceInPercent) } } $html -f ($tr -join '') | Out-File -append "C:\TEMP\$(get-date -Format "ddMMyyy.HHmm").html" -NoClobber