We help IT Professionals succeed at work.
Get Started

Output to HTML in powershell

Suresh Kumar
Suresh Kumar asked
on
454 Views
Last Modified: 2017-03-17
[cmdletbinding()]
param
(
    [Parameter(Position=0,ValuefromPipeline=$true)]
    [string[]$ComputerName = $env:ComputerName
 
)
 
$vers=Invoke-Command -ComputerName $ComputerName  -ScriptBlock { opcagt -version }
$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>"
$vers| ConvertTo-html -Head $a -body "<H2>Version </H2>" | Out-file -Filepath C:\tmp\ver.txt
echo $ComputerName ,$vers
invoke-Expression c:\tmp\ver.txt
$vers | ConvertTo-html -Head $a -body "<H2>Version </H2>" | Out-file -Filepath C:\tmp\ver.txt
Get-Content 'C:\tmp\ver.txt' | Foreach-Object {$_ -replace '^<html.*$', ("<html>")}| Set-Content 'C:\tmp\ver1.txt'
cat C:\tmp\ver1.txt


This script works fine in the remote computer to find the OV version .but when tried to get the output in HTML..it gives me a different output like PSCcomputerName,RunspaceId,PSShow ComputerName,Length

Can some one help me on this
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
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