title: Dynamically insert images in HTML file
body: <p>I try dynamically insert images in my HTML file, when I say dynamically it mean when it will be asked by a user, here 2 approce that I imagine, for both case user must before running the code put the images in a specific folder.</p>
  
  <p>Via a switch parameter like: <code>generate-html -includeImages</code>, if switch param is true then convert all images in MyImagefolder and insert one after one in my output. </p>
  
  <p>or</p>
  
  <p>Via a parameter that accept multiple value and in this case user must enter the images names like <code>generate-html -includeImages image1.gif, image2.gif</code></p>
  
  <p>Here the code that I use for insert one image to my HTML file:</p>
  
  <pre><code>$PSScriptRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
  $image = "$PSScriptRoot\img.gif"
  $ImageBits = [Convert]::ToBase64String((Get-Content $image -Encoding Byte))
  $ImageHTML = "&lt;img src=data:image/png;base64,$($ImageBits) alt='My Image'/&gt;"
  </code></pre>
  
  <p>Then I insert my variable in my <code>convertto-html</code> command.</p>
  
  <pre><code>ConvertTo-Html -Body $style -PreContent "$imageHTML" | Out-File "$PSScriptRoot\report.html"
  </code></pre>