Author Posts

March 29, 2016 at 3:14 am

My script makes multiple checks on remote machines like whether certain services are running, tasks are enabled, settings are set, groups exist. This time I would need to create some sort of report of the output rather than just display it on my screen . The output is of variable length hence difficult to format in a csv. Possibly html would be better as on consecutive runs I'll be only looking for deltas. My question is do I need to follow every line with something like convertto-html | out-file or is there a better way to consolidate the output and then pass it to out-file in the last step?

March 29, 2016 at 3:24 am

Gather all of your output in an array and then pipe your array to the ConvertTo-htlm

Simple example

$Arr = New-Object -TypeName System.Collections.Arraylist

Get-Service | foreach {$Arr.Add($_)} | Out-Null

Get-Process | foreach {$Arr.Add($_)} | Out-Null

$Arr | ConvertTo-Html | Out-File -FilePath $home\Documents\Report.html

March 29, 2016 at 5:51 am

Have a look at our HTML Reporting ebook, from the Resources menu here. It covers doing some fairly complex, multi-part reports.

I'll disagree with David on the array – an array is a poor way to do this, and gets slower the larger you make the array. Outputting custom objects to the pipeline, in a modular, function-based approach (which is how the ebook proceeds) is a much more PowerShell-native pattern.

March 30, 2016 at 9:43 am

HTML reporting, Networking Guide, Error handling and even DSC... wow! Funny I never checked that section. Thanks for pointing me there although the wife won't be happy I'll skip a couple of weekends out 😉