Use PowerShell
Real Admins Script
Real Admins Script
I’m updating Crystal Reports and trying to determine which reports might have been affected by some schema changes or functional changes in how the data was being stored.
The problem I’ve had is that when there are a large number of reports, it is very time consuming to open each one, look at it, and see if it contains any affected tables or views.
I’ve had to deal with this in my previous role as well. After feeling the pain a few times, I turned my intern loose on the problem and shelved the problem as “just another pain in dealing with Crystal Reports”.
Now, I’m back dealing with Crystal Reports more frequently and in the position to have to possibly update around 30 or 40 reports that were written before I started.
I’ve recently had a bit of exposure to the object model for the .NET API for Crystal Reports and thought maybe I could leverage that through PowerShell and whip together a quick script to help me list out the tables in each report.
It turned out to be painfully easy…
[reflection.assembly]::LoadWithPartialName('CrystalDecisions.Shared') [reflection.assembly]::LoadWithPartialName('CrystalDecisions.CrystalReports.Engine') $report = New-Object CrystalDecisions.CrystalReports.Engine.ReportDocument $report.load($pathToScript) $report.Database.Tables | Select-Object -expand Name $report.Dispose()
After I got the basics, I poked around and updated the script further (and posted it on PoshCode).
The full script also accesses the first level of subreports and retrieves their tables as well.
NOTE: Requires either the Crystal Report Runtime (Visual Studio 2008) or Visual Studio to be installed.
January 7, 2010 - 11:35 am
Thanks, Steven, this is exactly what I was trying to figure out during our last data model change. It’s definitely time for me to check out the .Net API for Crystal Reports and learn PowerShell!
January 7, 2010 - 11:41 am
Glad you found it useful. Let me know if you run in to any questions. I’ve been monkeying with the script a bit further as well (I should post the update later today.)
May 1, 2010 - 8:50 am
I am new to ps. we have hundreds of crystal reports currently kicked off by different platforms, such as crystal enterprise and java. we are looking for a solution to run all reports from 1 source, and is it possible to do it with ps? Is ps able to query sql tables so that we can pass values to crystal parameters? If so, can you please direct me where to start? can you please recommend some books or references? Thanks.