html - Powershell将主体转换为HTML主体

标签 html powershell powershell-2.0

我有一个脚本,用于查找文件夹以进行更新,如果有任何更新,则发送电子邮件。如何将电子邮件的正文更改或转换为URL或HTML链接而不是文本?

以下路径和服务器是示例。

这是我的脚本:

    Param (
    [string]$Path = "\\Desktop\Myfolder\status updates",
    [string]$SMTPServer = "smtp.myfolder.com",
    [string]$From = "Admin@me.com",
    [string]$To = "Admin@me.com",
    [string]$CC = "Admin@me.com",
    [string]$Subject = "New Status Report"
    )

$SMTPMessage = @{
    To = $To
    Cc = $cc
    From = $From
    Subject = "$Subject"
    Smtpserver = $SMTPServer    
}

$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-10) }
If ($File)
{   $SMTPBody = "`The following files have recently been added/changed.  Please copy and paste the following link to Windows Explorer:`n`n"
    $File | ForEach { $SMTPBody += "$($_.FullName)`n" }

    Send-MailMessage @SMTPMessage -Body $SMTPBody

最佳答案

PowerShell提供了一个Convert-ToHTML cmdlet,非常适合您的需求。

只需将内容$SMTPBody传送到其中即可。您甚至可以应用CSS文件来使电子邮件看起来更好一点。

$HTMLBody = ConvertTo-HTML -body $SMTPBody -CSSUri http://www.csszengarden.com/examples/style.css

然后在您的电子邮件中引用$HTMLBody

天空是CSS的极限。如果您想了解更多信息,请I covered this topic in a blog post。这是我们可以创建的示例。
enter image description here

在此示例中,我们使用-Pre-Post参数在表上方和下方添加内容。通过使用Convert-ToHTML属性将对象通过管道传递到-As Table中来创建表。仅包含四个参数的此cmdlet可以创建值得输出的网页!

关于html - Powershell将主体转换为HTML主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43854051/

相关文章:

javascript - 是否可以在框架或嵌入式视频中禁用 html?如果是,如何?

html - 为什么 tbody 的宽度等于此设置中第一个标题的宽度?

powershell - 如何使用 powershell 对 Active Directory 中的用户进行身份验证

windows - Powershell 启动 notepad.exe 并且命令窗口启动并消失

powershell - 如何使用 PowerShell 提取所有服务的 "Path to executable"

powershell - 将团队城市参数传递到 PowerShell 文件

javascript - jQuery:未捕获错误:语法错误,无法识别的表达式:(一堆照片标题文本数据)

HTML 表单 : Can submitted GET/POST parameters be suppressed using only HTML or CSS?

powershell - 在PowerShell代码中测试文件夹是否是连接点?

xml - 如果使用 PowerShell 不存在,如何添加属性?