1

我在我的部署过程中运行了几种不同类型的验证。对于每个验证,我想将一些 html 代码添加到数组中。在脚本的最后,我想取出整个代码数组并通过电子邮件发送出去。

我目前必须发送电子邮件的代码如下

$sendMessage = @{
    Subject = "Problem: Web Config Blanks"
    Body = "
        <p>The Deployment Validation script has found at least 1 problem</p>
        <UL>
            <LI> There are " + $errorWcBlanksCt + " web config values that are blank
        </UL>"
    From = "from@company.com"
    To = "to@company.com"
    SmtpServer = "0.0.0.0"
}
send-mailmessage @sendMessageWcBlanksCt -BodyAsHtml
Write-Host "Web config has been parsed and emailed"

显然,这只是用于检查 web.configs 中的空白值的验证。例如,如果我要添加对总文件数的验证,我怎么能有一个额外的<LI>行,但前提是文件数是脚本定义为“错误”的内容?

4

1 回答 1

1

在这种情况下,我将使用导出成功或错误的函数、验证标题和一些信息的函数进行测试。

Function Some-Test ($input){
   ...
   ... (some test that fails, so we set success.. maybe some notes)
   ... $success = $false
   New-Object -Type PSObject -Property @{
      Title = "Some Test"
      Success = $success
      Notes = $notes
   }
}

因此,稍后您将运行测试并添加到对象集合中,然后将其转换为 HTML:

$tests = @()

$tests += Some-Test $someServerorThing
$tests += Some-OtherTest $withSameOutputObjet

$emailbody = '<h1>Oh, I have some results to show you...</h1>'
$emailbody += $tests | ConvertTo-HTML -fragment
...
于 2013-08-27T14:08:17.793 回答