Powershell to HTML

03 August,2011 by Jack Vamvas

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

Convert to 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

Convert to html border 

Read More

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


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment on Powershell to HTML


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer