title: CSV comparison of Windows Services
body: <p>I'm fairly new to Powershell and I'm stuck with this portion of a much larger script. I need to pull all Windows Services and compare them to see if their Startup Type of Status has changed. If there were any changes, I need to count them so I can put that value in the body of an e-mail. Also, I need to attach an HTML report showing the previous and current state of the Windows services that changed.</p>
  <p>What I've done is the following:</p>
  <p>That piece of code generates a CSV file showing the current state of the services.</p>
  <pre><code>Get-Service | Select-Object -Property Name,DisplayName,StartType,ServiceType,Status | Export-Csv -Path &quot;C:\logs\after.csv&quot;
  </code></pre>
  <p>Then i declare two variables, one for the current state, another one for the &quot;template&quot;, the desired state of all Windows Services.</p>
  <pre><code>$before = Import-Csv -Path &quot;C:\logs\before.csv&quot;
  $after = Import-Csv -Path &quot;C:\logs\after.csv&quot;
  </code></pre>
  <p>Then, i compare both of them, parsing only those service that've changed and generate a CSS styled HTML report based on that</p>
  <pre><code>Compare-Object $before $after -Property Name,DisplayName,StartType,ServiceType,Status | ConvertTo-html -Head $css | Set-Content &quot;C:\logs\comparison.html&quot;
  </code></pre>
  <p>This is what i get:</p>
  <p><a href="https://i.stack.imgur.com/c82fH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c82fH.png" alt="enter image description here" /></a></p>
  <p>This is what it should look like:</p>
  <p><a href="https://i.stack.imgur.com/NLs7Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NLs7Y.png" alt="enter image description here" /></a></p>
  <p>Basically, i want to show the status of the latter CSV report in a new column after the Status column of the original CSV report. And I would also like to make a row count after that, so I can send an e-mail reporting HOW MANY services suffered any changes.</p>
  <p>Any help will be deeply appreciated.</p>