2 Replies Latest reply on Jan 4, 2019 3:06 PM by DZ1

    Conditional HTML tag for my PowerCLI report

    DZ1 Hot Shot

      I'm trying to create a conditional tag in my PowerShell/PowerCLI report.  I feel as though I'm missing something very simple.  I have reports with CSS and they come out correct, so I have an IF statement with an ID of 'Red' and I have the CSS color the background Red.  I'm certain that my CSS is not the problem, because I've used it for years, but the way I try and add the tag is causing problems (I think).  Here is what I have:


      $css = (gc C:\MyCSS.css)


      #$allVMs = Get-VM

      $AllReport = @()


      $allVMs | where { $_.PowerState -eq "PoweredOn" -and ($_ | Get-HardDisk).StorageFormat -ne "Thin" } | Sort Name | foreach {


          $vm = $_

          $disktype = ($vm | Get-HardDisk | select -ExpandProperty StorageFormat)


          $report = '' | Select Name, Disktype


          $report.Name = $vm.Name

          $report.Disktype = If ($disktype -ne 'Thin') { ("<a id='Red'>" + $disktype + "</a>") } #I"m sure this is the problem


          $allreport += $report


      $allreport | ConvertTo-Html -Head "<style>$css</style>" -Body @"


      <p><a id='Red'>This</a> is a test </p>


      "@ | Out-File C:\MyOutput\Report.html


      To make sure I had the CSS correct, I gave the word "This" the id tag of Red, and in my report its background color is red.  The problem is that the line that starts with $report.Disktype.  The tag is added, sort of.  When I look at the html, it shows this <tr><td>VMname</td><td>&lt;a id=&#39;Red&#39;&gt;EagerZeroedThick&lt;/a&gt;</td></tr>


      The HTML for the word "This" with the id of Red shows this for its HTML:

      <p><a id='Red'>This</a> is a test </p>


      I think it has something to do with the quotes, so I've tried making the double quotes single, and the singles double, I also tried using a subexpression, but that didn't work.  I also attached the HTML reports appearance, it shows the same in Firefox or Chrome.


      Any help is appreciated.