Hi all,<\/p>\n
Need some help with the below powerhshell query.<\/p>\n
The e-mail sends fine, but it outputs the HTML as plain text.<\/p>\n
I’ve tried adding $body += Converto-HTML but it doesn’t change anything. I can’t find anywhere where I can parse -BodyIsHTML also<\/p>\n
# mail message properties\n$fromemail = \"[email protected]\"\n$users = \"[email protected]\"\n$Subject = \"Disk Space Alert\"\n\n# smtp auth details\n$SMTPClient = \"smtp.office365.com\" \n$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)\n$SMTPClient.EnableSsl = $true\n$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(\"[email protected]\", \"smtp password\"); \n$SMTPClient.Send($fromemail, $users, $Subject, $body); \n\n# list properties\n$list = \"C:\\Users\\Desktop\\diskspacereport\\list.txt\" \n$computers = get-content $list \n[decimal]$thresholdspace = 20\n\n#assemble together all of the free disk space data from the list of servers and only include it if the percentage free is below the threshold we set above.\n$tableFragment= Get-WMIObject -ComputerName $computers Win32_LogicalDisk `\n| select __SERVER, DriveType, VolumeName, Name, @{n='Size (Gb)' ;e={\"{0:n2}\" -f ($_.size/1gb)}},@{n='FreeSpace (Gb)';e={\"{0:n2}\" -f ($_.freespace/1gb)}}, @{n='PercentFree';e={\"{0:n2}\" -f ($_.freespace/$_.size*100)}} `\n| Where-Object {$_.DriveType -eq 3 -and [decimal]$_.PercentFree -lt [decimal]$thresholdspace}\n\n# assemble the HTML for our body of the email report.\n$HTMLmessage = @\"\n<font color=\"\"black\"\" face=\"\"Arial, Verdana\"\" size=\"\"3\"\">\n<u><b>Disk Space Storage Report</b></u>\n<br>The server volume(s) listed below have less than $thresholdspace % free space. Volumes above this threshold will not be listed in this report.\n<br>\n<style type=\"\"text/css\"\">body{font: .8em \"\"Lucida Grande\"\", Tahoma, Arial, Helvetica, sans-serif;}\nol{margin:0;padding: 0 1.5em;}\ntable{color:#376;background:#CCC;border-collapse:collapse;width:647px;border:5px solid #525;}\nthead{}\nthead th{padding:1em 1em .5em;border-bottom:1px dotted #FFF;font-size:120%;text-align:left;}\nthead tr{}\ntd{padding:.5em 1em;}\ntfoot{}\ntfoot td{padding-bottom:1.5em;}\ntfoot tr{}\n#middle{background-color:#525;}\n</style>\n<body BGCOLOR=\"\"white\"\">\n$tableFragment\n</body>\n\"@ \n<\/code><\/pre>","upvoteCount":4,"answerCount":5,"datePublished":"2019-12-05T12:48:48.000Z","author":{"@type":"Person","name":"douglas-quaid","url":"https://community.spiceworks.com/u/douglas-quaid"},"acceptedAnswer":{"@type":"Answer","text":"Why not just Send-MailMessage with the -BodyAsHTML parameter?<\/p>","upvoteCount":3,"datePublished":"2019-12-05T14:07:37.000Z","url":"https://community.spiceworks.com/t/powershell-disk-space-report-wont-output-to-html/741854/2","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hi all,<\/p>\n
Need some help with the below powerhshell query.<\/p>\n
The e-mail sends fine, but it outputs the HTML as plain text.<\/p>\n
I’ve tried adding $body += Converto-HTML but it doesn’t change anything. I can’t find anywhere where I can parse -BodyIsHTML also<\/p>\n
# mail message properties\n$fromemail = \"[email protected]\"\n$users = \"[email protected]\"\n$Subject = \"Disk Space Alert\"\n\n# smtp auth details\n$SMTPClient = \"smtp.office365.com\" \n$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)\n$SMTPClient.EnableSsl = $true\n$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(\"[email protected]\", \"smtp password\"); \n$SMTPClient.Send($fromemail, $users, $Subject, $body); \n\n# list properties\n$list = \"C:\\Users\\Desktop\\diskspacereport\\list.txt\" \n$computers = get-content $list \n[decimal]$thresholdspace = 20\n\n#assemble together all of the free disk space data from the list of servers and only include it if the percentage free is below the threshold we set above.\n$tableFragment= Get-WMIObject -ComputerName $computers Win32_LogicalDisk `\n| select __SERVER, DriveType, VolumeName, Name, @{n='Size (Gb)' ;e={\"{0:n2}\" -f ($_.size/1gb)}},@{n='FreeSpace (Gb)';e={\"{0:n2}\" -f ($_.freespace/1gb)}}, @{n='PercentFree';e={\"{0:n2}\" -f ($_.freespace/$_.size*100)}} `\n| Where-Object {$_.DriveType -eq 3 -and [decimal]$_.PercentFree -lt [decimal]$thresholdspace}\n\n# assemble the HTML for our body of the email report.\n$HTMLmessage = @\"\n<font color=\"\"black\"\" face=\"\"Arial, Verdana\"\" size=\"\"3\"\">\n<u><b>Disk Space Storage Report</b></u>\n<br>The server volume(s) listed below have less than $thresholdspace % free space. Volumes above this threshold will not be listed in this report.\n<br>\n<style type=\"\"text/css\"\">body{font: .8em \"\"Lucida Grande\"\", Tahoma, Arial, Helvetica, sans-serif;}\nol{margin:0;padding: 0 1.5em;}\ntable{color:#376;background:#CCC;border-collapse:collapse;width:647px;border:5px solid #525;}\nthead{}\nthead th{padding:1em 1em .5em;border-bottom:1px dotted #FFF;font-size:120%;text-align:left;}\nthead tr{}\ntd{padding:.5em 1em;}\ntfoot{}\ntfoot td{padding-bottom:1.5em;}\ntfoot tr{}\n#middle{background-color:#525;}\n</style>\n<body BGCOLOR=\"\"white\"\">\n$tableFragment\n</body>\n\"@ \n<\/code><\/pre>","upvoteCount":4,"datePublished":"2019-12-05T12:48:48.000Z","url":"https://community.spiceworks.com/t/powershell-disk-space-report-wont-output-to-html/741854/1","author":{"@type":"Person","name":"douglas-quaid","url":"https://community.spiceworks.com/u/douglas-quaid"}},{"@type":"Answer","text":"