Answered by:
Write-Warning output on email body

Question
-
Hi
my Write-Warning to a txt looks like below
pcname.domain.net
pcname1.domain.net
pcname2.domain.net
But when i convert it to html and add that html file to mailbody it looks like
pcname.domain.net pcname1.domain.net pcname2.domain.net
How do i get the same out that i see on the txt file on my mailbody? Please help
Thursday, July 20, 2017 2:51 PM
Answers
-
You can't use ConvertTo-Html on a plain txt file. It only takes objects.
You do not need to save everything in files. Just use them in memory.
I suggest that you should learn PowerShell before trying to do advanced things.
$body = '<pre>' + (Get-content -Path C:\Reports\WSUSWarning.txt -Raw) + '</pre>'
You should not be using Write-Warning for this.
\_(ツ)_/
- Edited by jrv Thursday, July 20, 2017 4:04 PM
- Proposed as answer by Candy LuoMicrosoft contingent staff Friday, July 21, 2017 1:40 AM
- Marked as answer by PS GS Monday, August 21, 2017 9:44 AM
Thursday, July 20, 2017 4:03 PM -
<pre style="color: red;">\_(ツ)_/
- Marked as answer by PS GS Monday, August 21, 2017 9:44 AM
Sunday, July 23, 2017 4:17 PM
All replies
-
Wrap the text in "pre" tags and it will stay formatted when displayed as HTML.
\_(ツ)_/
Thursday, July 20, 2017 3:25 PM -
I am sorry, i am new to PS, could you please provide more info? Where i need to insert "pre"
} Catch {
$WarningPreference = “continue”
Write-Warning "$($Computer)"3>>C:\Reports\WSUSWarning.txtMy PS script looks like above
Thursday, July 20, 2017 3:50 PM -
<pre> text lines </pre>
\_(ツ)_/
Thursday, July 20, 2017 3:52 PM -
Thanks a lot, sorry again
my ps looks like below
} Catch {
$WarningPreference = “continue”
Write-Warning "$($Computer)"3>>C:\Reports\WSUSWarning.txtGet-content -Path C:\Reports\WSUSWarning.txt | ConvertTo-Html | Out-File C:\Reports\Test21.htm
Where i need to insert <pre> text lines </pre>
Thursday, July 20, 2017 3:55 PM -
You can't use ConvertTo-Html on a plain txt file. It only takes objects.
You do not need to save everything in files. Just use them in memory.
I suggest that you should learn PowerShell before trying to do advanced things.
$body = '<pre>' + (Get-content -Path C:\Reports\WSUSWarning.txt -Raw) + '</pre>'
You should not be using Write-Warning for this.
\_(ツ)_/
- Edited by jrv Thursday, July 20, 2017 4:04 PM
- Proposed as answer by Candy LuoMicrosoft contingent staff Friday, July 21, 2017 1:40 AM
- Marked as answer by PS GS Monday, August 21, 2017 9:44 AM
Thursday, July 20, 2017 4:03 PM -
Thanks a lot...All worked fineThursday, July 20, 2017 4:15 PM
-
Hello Friend,
Is there a way to change the font for C:\Reports\WSUSWarning.txt -Raw? in mailbody?
Sunday, July 23, 2017 4:10 PM -
<pre style="color: red;">\_(ツ)_/
- Marked as answer by PS GS Monday, August 21, 2017 9:44 AM
Sunday, July 23, 2017 4:17 PM -
Hi PS GS,
Was your issue resolved?
If the information provided was helpful, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.
Best Regards,
Candy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Monday, August 21, 2017 9:01 AM