使用Send-MailMessage格式化电子邮件中PowerShell脚本的Select Name,LastWriteTime输出,可以按照以下步骤进行:
$files = Get-ChildItem -Path "C:\Path\To\Files" -File
$fileInfo = $files | Select-Object Name, LastWriteTime
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "File Information"
$mailParams = @{
From = $from
To = $to
Subject = $subject
}
$body = $fileInfo | Format-Table -AutoSize | Out-String
$mailParams["Body"] = $body
Send-MailMessage @mailParams
完整的脚本示例:
$files = Get-ChildItem -Path "C:\Path\To\Files" -File
$fileInfo = $files | Select-Object Name, LastWriteTime
$from = "sender@example.com"
$to = "recipient@example.com"
$subject = "File Information"
$mailParams = @{
From = $from
To = $to
Subject = $subject
}
$body = $fileInfo | Format-Table -AutoSize | Out-String
$mailParams["Body"] = $body
Send-MailMessage @mailParams
这样,脚本将获取指定路径下文件的名称和最后修改时间,并将其格式化后发送到指定的收件人邮箱中。
领取专属 10元无门槛券
手把手带您无忧上云