Issue
I am working on a script that will ping a list of workstations and return add them to an array if they are offline. After they are added to an array the script then sends an email with the list of offline workstations. Here is the script so far
$list = Get-Content "C:\Users\$env:UserName\Desktop\workstations.txt"
ForEach ($_ in $list) {
$test = Test-Connection -BufferSize 32 -Count 1 -ComputerName $_ -Quiet
IF ($test -match "false") {
$offlinelist += ($_)
}
}
Send-MailMessage -To "me <me@me.com>" -From "you <you@you.com>" -Subject "Offline Workstations" -SmtpServer "smtp.me.com" -body "These workstations are offline: <br> $offlinelist" -BodyAsHtml
In its current form the code will send an email with a output that looks like this:
These workstations are offline:
test1test2
What I need it to look like is this:
These workstations are offline:
test1
test2
I know there is a way to do it with possibly New-Object
cmdlet or possibly the Format-Table
cmdlet. I am just not sure how to go about structuring the code. I have found several examples, but I am not able to make it work with the Send-MailMessage
cmdlet. Also, is it possible to stylize the body of the email with a different color font or face? Any help or example would be greatly appreciated. Thank you in advance.
Solution
In case anyone else comes across this in the future, I was able to solve my problem by adding a <br>
after the workstation name in the array:
$offlinelist += "$_ <br>"
This seems to work because of the BodyAsHtml
attribute in the Send-MailMessage
cmdlet. I am not sure if this is the correct way syntax wise, but it is working for me without error. Cheers!
Answered By - Ozar Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.