Don Jones’ Favorite PowerShell Cmdlets, Part 9 of 10: ConvertTo-HTML
I think we can all agree that bosses love reports, right? Check this out:
gwmi win32_service -comp Server2 | where { $_.StartMode -eq “Auto” -and $_.State -ne “Running” }
A list of all services on Server2 which should be running, but which aren’t. However, not a terribly great report for management - after all, they’re not likely to have PowerShell. Why not do this instead?
gwmi win32_service -comp Server2 | where { $_.StartMode -eq “Auto” -and $_.State -ne “Running” } | select name,state | convertto-html | out-file \\intranet\wwwroot\reports\notrunningserver2.html
An instant HTML-formatted report, copied right to my intranet Web server. But wait - there’s more.
Click past the fold for more…
Help ConvertTo-HTML
That’s right, read the friendly manual (RTFM - that’s where the “TFM” in my book’s title, Windows PowerShell: TFM, 2nd Edition, comes from). Notice all the cool options for ConvertTo-HTML? For example, you can insert CSS style sheet links into the head section of the output HTML - very cool, as it makes prettier reports for the boss. You could also specify a title for the report, or insert some explanatory text into the body section, just before your actual report info. Play around with it - ConvertTo-HTML is a fun, useful gadget to play with. We spend a lot of time in my classes seeing what it can do, in fact (want to come? www.ScriptingTraining.com/ilt/schedule.asp - I’ll see you there).
Don Jones is the Lead Scripting Guru for SAPIEN Technologies and a Windows PowerShell MVP. He’s the co-author of Windows PowerShell: TFM, 2nd Edition and is the Windows PowerShell columnist for TechNet Magazine. Don is also the Director for the new centralized, independent PowerShell online community: www.PowerShellCommunity.org.
Get your hands on the full Don Jones Favorite Cmdlets Series at this address:
http://www.realtime-windowsserver.com/type/mt-search.cgi?tag=don%20jones%20favorite%20cmdlets&blog_id=1

Email This!
Digg it!
Del.icio.us
Reddit!
Newsvine