Chad's profileChad Miller's BlogBlogListsNetworkMore Tools Help

Blog


    April 11

    Send Powershell output to an Excel, PDF, or Image file

    While reading through Wrox book, Professional SQL Server 2008 Reporting Services (SSRS) I noticed a chapter on "Integrating Reports Into Custom Applicaiton" where the authors make use of the ReportViewer control to embed an SSRS report in a WinForm application without needing an SSRS server. Since SSRS reports can use DataTables as a data sources I thought this would make a nice way to export the output of any Powershell command/script to a number of different formats natively supported by SSRS including Excel, PDF, and various image formats: BMP,EMF,GIF,JPEG,PNG or TIFF.
     
    In Searching for examples of ReportViewer WinForm implementations I found a very nice set of classes called ReportExporters by Andriy Protskiv which greatly simplify working with ReportViewer. Using ReportExporters I created an Out-Report script available on Poshcode. To use you'll need to install the Microsoft Report Viewer Redistributable, either the 2005 or 2008 version will work. I think Visual Studio and/or SSRS server includes the ReportViewer. I have both installed on my machine and did not need to install the Redistributable. You will also need to download or compile the ReportExporters dlls. You can grab the compiled version from demo code in the article.
     
    Here are few examples of what you can do with the script:
     
    get-alias | ./out-report.ps1 "c:\users\u00\documents\aliases.xls" xls
    get-alias | ./out-report.ps1 "c:\users\u00\documents\aliases.pdf" pdf
    get-alias | ./out-report.ps1 "c:\users\u00\documents\aliases.jpeg" -filetype image -imagetype JPEG -height 22 -width 11
     
    The script makes use of a DataTable routine by Marc van Orsouw (/\/\o\/\/) . I often use variations of the DataTable code in many of my scripts, especially for importing data into SQL Server tables.
     
    Andriy points out, not only can you generate Excel, PDF and images from the ReportViewer control, but you can also extended SSRS to support DOC, RTF, WordprocessingML, and OOXML. A little hacky, but interesting.
     

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Excellent
    Apr. 11

    Trackbacks

    The trackback URL for this entry is:
    http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!340.trak
    Weblogs that reference this entry
    • None