html - Powershell - 发送包含数组的电子邮件,需要将每个项目放在新行上
问题描述
当尝试发送包含在数组中收集的文件列表的电子邮件时,该数组将整个列表打印在一个字符串中。目标是将找到的文件列表打印在每个项目的新行上。
function SendReport
{
$rptDataPath = "C:\Maintenance\Logs\"
[array]$rptData = Get-ChildItem -Path "$rptDataPath" | select Name | Out-String
$smtpBody = "Below are the following files located in $rptDataPath <br><br> $rptFileList"
Send-MailMessage -SmtpServer $smtpServer -To $smtpRecipient -From $smtpSender -Subject $smtpSubject -Body $smtpBody -BodyAsHtml
}
SendReport
解决方案
iRon 提供的代码片段解决了我的问题。下面是我用来向需要目录中文件列表的收件人发送电子邮件的功能。谢谢您的帮助。
$smtpServer = "<Mail Server>"
$smtpRecipient = "Recipient Address"
$smtpSubject = "PowerShell Reporting HTML Example"
$smtpSender = "From or Spoofing Address"
function SendReport
{
$rptDataPath = "<Directory Path>"
$rptData = (Get-ChildItem -Path "$rptDataPath").name -join '<br>'
$smtpBody = "Below are the following files located in $rptDataPath <br> $rptData"
Send-MailMessage -SmtpServer $smtpServer -To $smtpRecipient -From $smtpSender -Subject $smtpSubject -Body $smtpBody -BodyAsHtml
}
SendReport
推荐阅读
- c# - ASP.NET-Core 应用程序根目录中的 NLog 日志文件
- google-sheets - ARRAYFORMULA 不添加到每一行
- echarts - 如何在echarts中使用本地图片?
- node.js - 使用 Glob 和 Node.js 选择指定目录及以下目录中某些扩展名的所有文件
- python - Python日期生成未生成正确的日期
- reactjs - (React) useParams 获取 id 并从列表中显示
- javascript - 如何通过单击兄弟元素或父元素来获取 dom 的某个部分
- php - 我如何获取 IMAP 收件箱并将其保存到 codeigniter 中的数据库?
- r - 从 R 中的经纬度列表创建多边形
- python-3.x - Netmiko 异步连接 100 台设备