I am working on a health check PowerShell script that is generating an HTML file. Now, I want to update the solution where If I run the same script again (as a post check) it should create maybe another html file with the new health check values and old file values should also be there. This is to compare what changed during the day in the system. Please let me know how to append the new data in the old/existing html file.
I have written below code to generate health check report.
$ServHead = ConvertTo-HTML -AS Table -Fragment -PreContent '<H2>Services Information</H2>'|Out-String
# Gathers information on Services. Displays the service name, System name of the Service, Start Mode, and State. Sorted by Start Mode and then State.
$Service = Get-WmiObject win32_service -ComputerName $computer | Select-Object DisplayName, Name, StartMode, State | sort StartMode, State, DisplayName | ConvertTo-HTML -Fragment
# create an html output file
ConvertTo-HTML -Head $Style -PostContent "$ReportHead $Service " -Title "System Health Check Report" | Out-File "C:\HealthCheck\$computer\Health Report $CurrentDate.html"
so, the requirement is if we run the script again it should append the latest values so that we can compare what was the earlier state of the service and what is now. Please let me know how to append the new data in the old/existing html file ?
I am looking for an additional column to compare the previous and current output in the same file - e.g. - Service | Status | New Status so, previous execution will fill 'Service' and 'Status' details and in next execution (maybe after some hours) the services latest status should come under 'New Status'
Import-Csv
and add the new column for 'New Status'. Once done, convert that to HTML. By the way, which version of PowerShell are you actually running?