When deploying SSRS reports, one needs to check whether the fonts used in a .rdl report are actually installed on the SSRS server, as a developer may select fonts installed by software that is not available on the server (I’m looking at YOU, Arial Narrow).
A font declaration inside an .rdl file looks like this
<Style> <FontFamily>Arial Narrow</FontFamily> <FontSize>8pt</FontSize> </Style>
and those elements reside in the
<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition">
namespace.
First, we load the .rdl as XML and declare the namespace
[xml] $rdl = get-content "c:\path\to\my.rdl"
$ns = @{ r ="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" };
As we need to select all Style elements containing the FontFamily AND the FontSize child elements, we query the XML
$rdl.Report.Body | select-xml "//r:Style[r:FontFamily and r:FontSize]" -namespace $ns
and then select the text values
| foreach-object { "$($_.Node.FontFamily) $($_.Node.FontSize)" }
This returns a list of font specifications like this
Arial Narrow 8pt Arial Narrow 8pt Arial Narrow 8pt Arial Black 8pt Arial Black 8pt Arial Black 8pt Arial Black 8pt Arial Black 8pt
Grouping the list and counting the items
| Group-Object | select-object name, count
returns
Name Count ---- ----- Arial Narrow 8pt 20 Arial Black 8pt 6
So this is the script:
[xml] $rdl = get-content "c:\path\to\my.rdl"
$ns = @{ r ="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition" };
$rdl.Report.Body
| select-xml "//r:Style[r:FontFamily and r:FontSize]" -namespace $ns
| foreach-object { "$($_.Node.FontFamily) $($_.Node.FontSize)" }
| Group-Object | select-object name, count
Posted by devio 