1

I am running several different types of validations on my deployment process. For each validation I'd like to add some html code to an array. At the end of the script I'd like to take the entire array of code and email it out.

The code I currently have to send the email is the following

$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 = "[email protected]"
    To = "[email protected]"
    SmtpServer = "0.0.0.0"
}
send-mailmessage @sendMessageWcBlanksCt -BodyAsHtml
Write-Host "Web config has been parsed and emailed"

Obviously this one is just for a validation that checks blank values in web.configs. If I were to add in a validation for total file count for example, how could I have an additional <LI> line, but only if the file count is what the script defines as "wrong"?

4
  • What version of powershell are you using? Use the "host" command to find out if you don't know off hand. Commented Aug 23, 2013 at 16:35
  • 2.0 however it's possible that I may have to run this script on a 1.0 server Commented Aug 23, 2013 at 16:37
  • 2
    Just a suggestion, but I make a $collection = @() and then I add objects $collection += New-PSOBject{title="value"... and then I pipe the collection to | ConvertTo-HTML and I use that as the body. Add some inline CSS to pretty it up - much easier than building my own HTML. Commented Aug 23, 2013 at 18:09
  • so in this case would the collection be <LI> There are " + $errorWcBlanksCt + " web config values that are blank and I would simply make it body = "<p>The Deployment Validation...</p><UL> $collection </UL> Commented Aug 23, 2013 at 18:12

1 Answer 1

1

In this case I would make tests from functions that export a Success that is true or false, a validation title, and some info.

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
   }
}

So later you would run the tests and add to a collection of objects, then convert that to a 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
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.