MessageBox Output , Convertto-HTML

Hello,

In a script I use a messagbox to ask for Input.
This input wil be saved in a variable.
This variabele I like to convert to HTML, only when I look at the result in HTML
this is not making sense for me.

Hopefully someone can point out, what I need to change to make it work .

$msgBoxInput =  [System.Windows.MessageBox]::Show( "Virtual Machine Host is managed at PBA ? `n",
 'VMHost managed by PBA','YesNoCancel','QUESTION')

  switch  ($msgBoxInput) {

    'Yes' {
        ## Do 
        $VMH = 'The Host of the VM is managed at  PBA'
        }
    'No' {
        ## Do 
       $VMH = 'The Host of the VM is NOT managed at PBA'
        }
    'Cancel' {
        ## Do
       $VMH = 'No answer was given '
        }
         }

#Convert VMHOST Information to HTML  $VMH | ConvertTo-Html -as Table -PreContent "<h2> VHMOST Information</h2>" -Fragment

$VMHTML  =$VMH | Convertto-HTML  | out-file .\path\name.html

Messagebox

This might help you …

Another option is to convert the string to an object. If you are going to be doing a lot of this, you could write that into a function. That is the route I took.

No idea if this is what you meant to be honest.

After trial and error I end up with this:

#Convert VMHOST Information to HTML 
$VMH = $(
If($VMH -eq "Yes"){
 [PSCustomobject]@{'Host'= "The Host of the VM is managed " } 
 }
 Elseif($VMH -eq "No"){
 [pscustomobject]@{'Host'= "The Host of the VM is NOT managed "}
 }
 Else {
 [pscustomobject]@{'Host'= "No Valid Answer is Given "
 }
  }
 ) |  ConvertTo-Html -as Table -PreContent "<h2> VHMOST Information</h2>" -Fragment