We help IT Professionals succeed at work.
Get Started

Powershell and ConvertTo-HTML

campbell1972 asked
Last Modified: 2017-03-30
Puzzled by another issue with different outputs when running a script from Powershell ISE compared to a standard shell.

I am performing a number of SQL checks and formatting the resultset as an HTML fragment:

$html1 = $dataset1.Tables .......... ConvertTo-HTML -AS Table -fragment -PreContent '<h2>SQL Configuration</h2>' | Out-String

These fragments are then associated with variables covering each block of tests:

$svrconfig = $html1, $html2
$memory = $html3,$html4

The main body of HTML is defined as a variable (a$) containing div blocks for each of the variables listed above:

<div id+""Server Configuration"" class=""tabcontent"">" + $memory +"</div>

When running the final convert under ISE, a complete HTML document is produced with the variables in the div blocks being correctly substituted with the relevant HTML.

However, when executed under a standard Powershell shell with administrative rights, the final HTML conversion does not see the div variables being populated:

ConvertTo-HTML -body $a | Out-File -append $SQLStatusReport

As usual, any pointers gratefully received!

Watch Question
PowerShell Developer
Top Expert 2010
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE