MDSPackageComparator.psm1
<#
.SYNOPSIS This command will compare the 2 Master Data Service(MDS) Package 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 MDS Package 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 OriginalMDSPackage The second set contains the Objects that are either Extra or Changed from ChangedMDSPackage The Results sometimes might not be straight forward, as a result when File Option is chosen , the XML's for both the MDS Package 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 OriginalMDSPackagePath Accepts the path where First / Original MDS Package file is placed .PARAMETER ChangedMDSPackagePath Accepts the path where Second / Changed MDS Package is placed. .PARAMETER ResultOutput Accepts either Console or File, to determine where result is to be shown / placed. .EXAMPLE Compare-MDSPackage -OriginalMDSPackagePath 'C:\Users\SSAS\AdventureWorksDev.pkg' -ChangedMDSPackagePath 'C:\Users\SSAS\AdventureWorksTest.pkg' -ResultOutput Console -Verbose Compare-MDSPackage -OriginalMDSPackagePath 'C:\Users\SSAS\AdventureWorksDev.pkg' -ChangedMDSPackagePath 'C:\Users\SSAS\AdventureWorksTest.pkg' -ResultOutput File -Verbose #> Function Compare-MDSPackage { Param ( [Parameter(Mandatory=$true)] [string] $OriginalMDSPackagePath , [Parameter(Mandatory=$true)] [string] $ChangedMDSPackagePath, [Parameter(Mandatory=$true)] [ValidateSet('Console','File')] [string] $ResultOutput ) $Stopwatch = [system.diagnostics.stopwatch]::StartNew() Write-Verbose 'Starting Process of Comparing MDS Package' $Counter = 1 Write-Verbose 'Reading MDS Package Files' $MDSPkg1Path = $OriginalMDSPackagePath $MDSPkg2Path = $ChangedMDSPackagePath Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)" FUNCTION GenerateXML ( [string] $MDSPkgPATH , [int] $Cnt ) { $CopyPath = $MDSPkgPATH.Substring(0, $MDSPkgPATH.lastIndexOf('\')) $OriginalFileNm = (Get-Item -Path $MDSPkgPATH).Name $XMLFileNm=$OriginalFileNm.Substring(0, $OriginalFileNm.LastIndexOf('.')) $CopyPathM = $CopyPath + '\' + $Cnt + $XMLFileNm+'.XML' Copy-Item -Path $MDSPkgPATH -Destination $CopyPathM -Force $XMLA= Get-Content -Path $CopyPathM | %{$i = 1} { new-object psobject -prop @{LineNum=$i;Text=$_}; $i++} Return $XMLA } $MDSPkg1 = GenerateXML -MDSPkgPATH $MDSPkg1Path -Cnt $Counter $Counter = $Counter + 1 $MDSPkg2 = GenerateXML -MDSPkgPATH $MDSPkg2Path -Cnt $Counter Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)" $Difference = Compare-Object $MDSPkg1 $MDSPkg2 -Property Text -PassThru $Result_File1 = $Difference | Where-Object -Property SideIndicator -EQ "<=" $Result_File2 = $Difference | Where-Object -Property SideIndicator -EQ "=>" $ResultPath = $MDSPkg1Path.Substring(0, $MDSPkg1Path.lastIndexOf('\')) IF($ResultOutput -eq 'Console') { Write-Host 'Changes / Addtions in Original MDS Package' $Result_File1 | Select-Object LineNum,Text Write-Host 'Changes / Addtions in Changed MDS Package' $Result_File2 | Select-Object LineNum,Text } Else { $Result1Path = $ResultPath + '\' + 'Results_Changed_Or_Additional_Components_in_OriginalMDSPackage.txt' $Result2Path = $ResultPath + '\' + 'Results_Changed_Or_Additional_Components_in_ChangedMDSPackage.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 MDS Package for Original and Changed are also created with results on the same path as that of Original MDS Package ' Write-Verbose "Results for Changes / Addtion in Original MDS Package is placed on : $($Result1Path)" Write-Verbose "Results for Changes / Addtion in Changed MDS Package is placed on : $($Result2Path)" } Write-Verbose 'Process Complete' Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)" } Export-ModuleMember -Function Compare-MDSPackage |