03 August,2011 by Tom Collins
I use Powershell for standardised scripts across the server inventory such as running a job collection, security audit or performance statistics collection. Powershell to HTML is another option of displaying data and distrinuting to users.
Normally, I either save out the results in an Excel spreadsheet or a text file. I save out in an Excel spreadsheet if some data manipulation is required or a text file if it’s a notification .
An example of using Excel as the output device is a sql server security audit – the server owner will receive an Excel spreadsheet of all users on the database server.
Powershell to HTML file allows the benefits of a web based reporting system. Other benefits include HTML formatting.
The ConvertTo-Html Cmdlet does the job.
This Powershell script : a) creates an output device called “computer_info_<current_iso_date>.html” in the current path
b) lists all the processes on the computer
$isodate=Get-Date -format s $isodate=$isodate -replace(":","") $basepath=(Get-Location -PSProvider FileSystem).ProviderPath $outputfile="\computer_info_" + $isodate + ".html" $outputfilefull = $basepath + $outputfile Get-Process | ConvertTo-Html | Set-Content $outputfilefull
Output in HTML
Notice how the output is basic. HTML is great for style. To add a “border = 1” and make the information easier to scan use this script – which is similar to the above scripts with some adjustments.
$isodate=Get-Date -format s $isodate=$isodate -replace(":","") $basepath=(Get-Location -PSProvider FileSystem).ProviderPath $outputfile="\computer_info_" + $isodate + ".html" $outputfilefull = $basepath + $outputfile $style="" Get-Process | ConvertTo-Html -head $style| Set-Content $outputfilefull
Output in HTML
Powershell sql server security audit
SQL Server – Send email using Powershell - SQL Server DBA
SQL Server - Powershell and SQL Error Logs
SQL Server DBA Top 10 automation tasks
SQL Server - Top 10 DBA mistakes
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |