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.

DOWNLOAD UPDATED SCRIPT

DOWNLOAD VERSION FOR POWERSHELL V1

Want more great reading? Check out my reading list!