Link to home
Start Free TrialLog in
Avatar of hchabria
hchabriaFlag for India

asked on

How to convert .log file to .html file using PowerShell

I am using PowerShell to check the services status of a server. I am storing the result in a .log file called "ServiceTesting.log" (please see the attachment).

Now the problem is that when I am trying to convert the log file into HTML file called "report.htm", I am not getting the content of the log file in that html file. It's giving some differnt output with different column name. Request you to help me on that so that I can get the desired output. ServiceTesting.log report.htm
$log_file="z:\ServiceTesting.log"
Clear-Content $log_file
$head = @'
	<style>
		BODY{font-family:Verdana; background-color:lightblue;} 
			TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} 
				TH{font-size:1.3em; border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:#FFCCCC} 
					TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:yellow}
	</style>
'@
$header = "<H1>Service Status</H1>"
$title = "Service Status"
Get-Service | Select-Object Status, Name, DisplayName >> $log_file
Get-Content $log_file | ConvertTo-HTML -head $head -body $header -title $title | Out-File z:\report.htm
& "z:\report.htm" #This will popup the htm file

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of soostibi
soostibi
Flag of Hungary image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hchabria

ASKER

Excellent. Thank you very much for your valuable support. However, it will be very helpful if you could provide the code that will directly convert the .log file to .htm file.

The reason I am asking for is that I have various PS scripts that store output to .log files and I want to convert those .log files directly to .htm files.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial