SSRSRDLComparator.psm1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
<#
.SYNOPSIS This command will compare the 2 SSRS RDL Files and generate a result in XML format in either Console Window or on a Source File path .DESCRIPTION The Result can be generated on either Console or File. This can be decided by The options provided in ResultOuput Property The Result is a comparision of the XML files generated of the SSRS RDL files. The Result contains 2 sets with the Line Number and the text for which there is a mismatch The first set contains the Objects that are either Extra or Changed from OriginalRDL The second set contains the Objects that are either Extra or Changed from ChangedRDL The Results sometimes might not be straight forward, as a result when File Option is chosen , the XML's for both the SSRS RDL files are available on the path where Result is generated. This XML can now be used along with the Results XML as they can be useful to understand the differnces more clearly. Use "Verbose" Option to get more details about the Operation / Process performed, as Comparision might take some time .PARAMETER OriginalRDLPath Accepts the path where First / Original SSRS RDL file is placed .PARAMETER ChangedRDLPath Accepts the path where Second / Changed SSRS RDLis placed. .PARAMETER ResultOutput Accepts either Console or File, to determine where result is to be shown / placed. .EXAMPLE Compare-SSRSRDL -OriginalRDLPath 'C:\Users\SSAS\AdventureWorksDev.RDL' -ChangedRDLPath 'C:\Users\SSAS\AdventureWorksTest.RDL' -ResultOutput Console -Verbose Compare-SSRSRDL -OriginalRDLPath 'C:\Users\SSAS\AdventureWorksDev.RDL' -ChangedRDLPath 'C:\Users\SSAS\AdventureWorksTest.RDL' -ResultOutput File -Verbose #> Function Compare-SSRSRDL { Param ( [Parameter(Mandatory=$true)] [string] $OriginalRDLPath , [Parameter(Mandatory=$true)] [string] $ChangedRDLPath, [Parameter(Mandatory=$true)] [ValidateSet('Console','File')] [string] $ResultOutput ) $Stopwatch = [system.diagnostics.stopwatch]::StartNew() Write-Verbose 'Starting Process of Comparing RDL' $Counter = 1 Write-Verbose 'Reading RDL Files' $RDL1Path = $OriginalRDLPath $RDL2Path = $ChangedRDLPath Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)" FUNCTION GenerateXML ( [string] $RDLPATH , [int] $Cnt ) { $CopyPath = $RDLPATH.Substring(0, $RDLPATH.lastIndexOf('\')) $OriginalFileNm = (Get-Item -Path $RDLPATH).Name $XMLFileNm=$OriginalFileNm.Substring(0, $OriginalFileNm.LastIndexOf('.')) $CopyPathM = $CopyPath + '\' + $Cnt + $XMLFileNm+'.XML' Copy-Item -Path $RDLPATH -Destination $CopyPathM -Force $XMLA= Get-Content -Path $CopyPathM | %{$i = 1} { new-object psobject -prop @{LineNum=$i;Text=$_}; $i++} Return $XMLA } $RDL1 = GenerateXML -RDLPATH $RDL1Path -Cnt $Counter $Counter = $Counter + 1 $RDL2 = GenerateXML -RDLPATH $RDL2Path -Cnt $Counter Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)" $Difference = Compare-Object $RDL1 $RDL2 -Property Text -PassThru $Result_File1 = $Difference | Where-Object -Property SideIndicator -EQ "<=" $Result_File2 = $Difference | Where-Object -Property SideIndicator -EQ "=>" $ResultPath = $RDL1Path.Substring(0, $RDL1Path.lastIndexOf('\')) IF($ResultOutput -eq 'Console') { Write-Host 'Changes / Addtions in Original RDL' $Result_File1 | Select-Object LineNum,Text Write-Host 'Changes / Addtions in Changed RDL' $Result_File2 | Select-Object LineNum,Text } Else { $Result1Path = $ResultPath + '\' + 'Results_Changed_Or_Additional_Components_in_OriginalRDL.txt' $Result2Path = $ResultPath + '\' + 'Results_Changed_Or_Additional_Components_in_ChangedRDL.txt' $Result_File1 | Select-Object LineNum,Text | Out-File -FilePath $Result1Path $Result_File2 | Select-Object LineNum,Text | Out-File -FilePath $Result2Path Write-Verbose 'Results are generated in XML Format , However if a comparision is not clear 2 Extra XML Files of RDL for Original and Changed are also created with results on the same path as that of Original RDL ' Write-Verbose "Results for Changes / Addtion in Original RDL is placed on : $($Result1Path)" Write-Verbose "Results for Changes / Addtion in Changed RDL is placed on : $($Result2Path)" } Write-Verbose 'Process Complete' Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)" } Export-ModuleMember -Function Compare-SSRSRDL |