Arrays 将HTML代码添加到powershell数组中

Arrays 将HTML代码添加到powershell数组中,arrays,powershell,sendmail,Arrays,Powershell,Sendmail,我正在部署过程中运行几种不同类型的验证。对于每个验证,我想向数组中添加一些html代码。在脚本的最后,我想把整个代码数组通过电子邮件发送出去 我目前必须发送电子邮件的代码如下 $sendMessage = @{ Subject = "Problem: Web Config Blanks" Body = " <p>The Deployment Validation script has found at least 1 problem</p>

我正在部署过程中运行几种不同类型的验证。对于每个验证,我想向数组中添加一些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"
$sendMessage=@{
主题=“问题:Web配置空白”
正文=”
部署验证脚本发现至少1个问题

  • 存在为空的“+$errorWcBlanksCt+”web配置值
” From=”from@company.com" To=”to@company.com" SmtpServer=“0.0.0.0” } 发送mailmessage@sendMessageWcBlanksCt-BodyAsHtml 写入主机“已解析Web配置并通过电子邮件发送”

显然,这只是用于检查web.configs中空白值的验证。例如,如果我要为总文件计数添加一个验证,我怎么可能有一个额外的
  • 行,但前提是文件计数是脚本定义为“错误”的?在这种情况下,我将从导出正确或错误的成功、验证标题和一些信息的函数中进行测试

    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
    ...
    
    $tests=@()
    $tests+=sometest$someServerorThing
    $tests+=使用SameOutputObject的其他测试$
    $emailbody='哦,我有一些结果要给你看…'
    $emailbody+=$tests |转换为HTML-片段
    ...
    
    在本例中,我将对导出成功(正确或错误)、验证标题和一些信息的函数进行测试

    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
    ...
    
    $tests=@()
    $tests+=sometest$someServerorThing
    $tests+=使用SameOutputObject的其他测试$
    $emailbody='哦,我有一些结果要给你看…'
    $emailbody+=$tests |转换为HTML-片段
    ...
    
    您使用的powershell版本是什么?使用“host”命令来确定您是否立即知道。2.0但是我可能必须在1.0服务器上运行此脚本只是一个建议,但我提出了$collection=@()然后添加对象$collection+=New PSOBject{title=“value”…然后我将集合通过管道传输到| ConvertTo HTML,并将其用作主体。添加一些内联CSS来美化它-这比构建自己的HTML要容易得多。因此,在这种情况下,集合将是
  • 有“+$errorWcBlanksCt+”web配置值为空
  • ,我只需将其设置为
    body=“部署验证…

      $collection
    您使用的powershell的哪个版本?使用“host”命令了解您是否不知道是否已掌握。2.0但是,可能我可能只需在1.0服务器上运行此脚本,只是一个建议,但我制作了$collection=@()然后添加对象$collection+=新的psoObject{title=“value”…然后我将集合通过管道传输到| ConvertTo HTML,并将其用作主体。添加一些内联CSS来美化它-这比构建自己的HTML要容易得多。因此,在这种情况下,集合将是
  • 有“+$errorWcBlanksCt+”web配置值是空的
  • ,我只需将其设置为
    body=“部署验证…

      $collection