# Convertto-EnhancedHTMLFragment

**URL:** <https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166>\
**Category:** PowerShell Help\
**Created:** [March 2, 2017, 2:08am UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166 "2017-03-02T02:08:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![karan](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@karan](https://forums.powershell.org/u/karan)\
**Post date:** [March 2, 2017, 2:08am UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166/1 "2017-03-02T02:08:06Z")

</div>

Hello,

I need small help , in converting normal string to html format using convertto-enhancedhtml

Below is a sample code I am using. I want to output couple of variables in html page for multiple servers but I am not able to do that. What change do I need to make in the code.

I am getting the output in desired format but instead of the variables I get length value of the string.

* * *

$css = @"

body {

```
font-family:tahoma;
font-size:10pt;
color:#333;
padding:10px;

```

}

h1 {  
text-allign:center;  
border-top:1px solid #666;  
border-bottom:1px solid #666;  
}

h2 {

```
background-color:#666;

```

}  
h3{  
background-color:white;

}

"@

$server = ‘wdcqvap21’  
foreach ($computer in $server){

```
   [string]$a1 = Write-Output "Parameter file has been renamed for $computer !!"
    $frag1 = $a1 |ConvertTo-EnhancedHTMLFragment -as list | out-string

  [String]$a2 = Write-Output "Parameter file has been ammended for $computer !!"
    $frag2 = $A2 | ConvertTo-EnhancedHTMLFragment -as list | Out-String

      ConvertTo-EnhancedHTML -CssStyleSheet $css -HTMLFragments "$computer","$frag1","$FRAG2" | Out-File "c:\temp\syz.html"
}

```

---

<div class="post-metadata">

**Author:** ![karan](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@karan](https://forums.powershell.org/u/karan)\
**Post date:** [March 2, 2017, 2:54am UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166/2 "2017-03-02T02:54:48Z")

</div>

I am able to get the desired output using convertto-html ,but I want to use convertto-enhancedHTMLFragments for the same piece of code, so that I can highlight cells that do not meet the condition and this can happen only if I use EnhancedHTMLFragments.

* * *

$css = @"

body {

```
font-family:tahoma;
font-size:8pt;
color:#333;
padding:10px;

```

}

h1 {  
text-allign:center;  
border-top:1px solid #666;  
border-bottom:1px solid #666;  
}

h2 {

```
background-color:#999;

```

}  
h3{  
background-color:white;

}

"@

$server = ‘wdcqvap21’  
foreach ($computer in $server){

```
    $frag1 = ConvertTo-Html -as list -PreContent "Parameter file has been renamed for $server" | out-string

    $frag2 = ConvertTo-html -as List -PreContent "Parameter file has been amended for $server" | Out-String

      ConvertTo-HTML -head $css -body "$computer",$frag1,$frag2 | Out-File "c:\temp\syz.html"
}

```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 2, 2017, 9:23am UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166/3 "2017-03-02T09:23:30Z")

</div>

PLEASE use the code formatting tags, as listed in the bullets above the posting text box. It makes your code a lot easier to follow. Thank you.

In this line:

```
ConvertTo-EnhancedHTML -CssStyleSheet $css -HTMLFragments "$computer","$frag1","$FRAG2" | Out-File "c:\temp\syz.html
```

There’s no need to include the variables in quotation marks.

But, more specifically:

```
[String]$a2 = Write-Output "Parameter file has been ammended for $computer !!"
$frag2 = $A2 | ConvertTo-EnhancedHTMLFragment -as list | Out-String
```

The EnhancedHTML commands are expecting objects as input. They’re designed to enumerate the object’s properties to construct a list or table. You’re passing in a string, which has a Length property, and so that’s what you’re getting. The commands weren’t designed to just display simple messages like this. You’re also going through a real unnecessary set of steps.

```
$a2 = "Parameter file has been ammended for $computer !!"
```

Is sufficient, and you can use $a2 in the fragment list for ConvertTo-EnhancedHTML.

---

<div class="post-metadata">

**Author:** ![fpoli](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/fpoli/32/331_2.png) [@fpoli](https://forums.powershell.org/u/fpoli)\
**Post date:** [March 2, 2017, 10:22am UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166/4 "2017-03-02T10:22:15Z")

</div>

may is say that long hard road would be this, but as Don said, will simply increase you script complexity:

```
foreach ($computer in $server){

[string]$a1 = Write-Output "Parameter file has been renamed for $computer !!"
[String]$a2 = Write-Output "Parameter file has been ammended for $computer !!" 

$props = @{ 'Renamed'= $a1 ;
            'Ammended'= $a2
          }
$Processed = New-Object -TypeName PSObject -Property $props

$params = @{'As'='list';
            'Properties'= 'Computer',
             @{n='Renamed';e={$_.renamed}},
             @{n='Ammended';e={$_.ammended}}
            }
           
$frags = ConvertTo-EnhancedHTMLFragment -InputObject $Processed $params

ConvertTo-EnhancedHTML -CssStyleSheet $css -HTMLFragments $computer,$frags | Out-File "c:\temp\syz.html"
}
```

---

<div class="post-metadata">

**Author:** ![karan](https://avatars.discourse-cdn.com/v4/letter/k/58f4c7/32.png) [@karan](https://forums.powershell.org/u/karan)\
**Post date:** [March 6, 2017, 2:00am UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166/5 "2017-03-06T02:00:35Z")

</div>

Thanks a lot for the clarity !!! 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/convertto-enhancedhtmlfragment/8166/6 "2024-05-16T20:39:54Z")

</div>

Closed on May 16, 2024, 8:39pm UTC


