当前位置: 动力学知识库 > 问答 > 编程问答 >

powershell - Get data from text file and send an email in table format

问题描述:

I have a text file with data as below

ServerName1|Status1

ServerName2|Status2

.

.

.

ServerNamen|Statusn

I have to email the above text in table format using PowerShell. SMTP is already configured.

Email is to be in table format of the above.

网友答案:

As hinted by Ansgar, you can utilize Import-Csv to read the text file into objects, and then ConvertTo-Html to produce the table for the email:

$StatusTable = Import-Csv .\status.txt -Delimiter '|' -Header Server,Status | ConvertTo-Html -As Table
Send-MailMessage -Body $StatusTable -BodyAsHtml ...
分享给朋友:
您可能感兴趣的文章:
随机阅读: