DTSXComparator.psm1

<#
     .SYNOPSIS
         This command will compare the 2 DTSX 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 DTSX 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 OriginalDTSX
         The second set contains the Objects that are either Extra or Changed from ChangedDTSX
         The Results sometimes might not be straight forward, as a result when File Option is chosen , the XML's for both the DTSX 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 OriginalDTSXPath
     Accepts the path where First / Original DTSX file is placed
  
   
  
     .PARAMETER ChangedDTSXPath
     Accepts the path where Second / Changed DTSX is placed.
  
   
  
     .PARAMETER ResultOutput
     Accepts either Console or File, to determine where result is to be shown / placed.
  
   
  
     .EXAMPLE
      Compare-DTSX -OriginalDTSXPath 'C:\Users\SSIS\AdventureWorksDev.DTSX' -ChangedDTSXPath 'C:\Users\SSIS\AdventureWorksTest.DTSX' -ResultOutput Console -Verbose
      Compare-DTSX -OriginalDTSXPath 'C:\Users\SSIS\AdventureWorksDev.DTSX' -ChangedDTSXPath 'C:\Users\SSIS\AdventureWorksTest.DTSX' -ResultOutput File -Verbose
  
   
  
#>



Function Compare-DTSX
{

 

    Param 
    (
    [Parameter(Mandatory=$true)]
    [string] $OriginalDTSXPath ,
    [Parameter(Mandatory=$true)]
    [string] $ChangedDTSXPath,
    [Parameter(Mandatory=$true)]
    [ValidateSet('Console','File')]
    [string] $ResultOutput

 

    )

 

    $Stopwatch = [system.diagnostics.stopwatch]::StartNew()
    
    Write-Verbose 'Starting Process of Comparing DTSX'
    
    $Counter = 1
    
    Write-Verbose 'Reading DTSX Files'
    
    $DTSX1Path = $OriginalDTSXPath
    $DTSX2Path = $ChangedDTSXPath

 

    Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)"

 

    FUNCTION GenerateXML ( [string] $DTSXPATH ,  [int] $Cnt )
    {
        $CopyPath = $DTSXPATH.Substring(0, $DTSXPATH.lastIndexOf('\'))
        $OriginalFileNm = (Get-Item -Path $DTSXPATH).Name
        $XMLFileNm=$OriginalFileNm.Substring(0, $OriginalFileNm.LastIndexOf('.'))
        $CopyPathM = $CopyPath + '\' + $Cnt + $XMLFileNm+'.XML'
        
        Copy-Item -Path $DTSXPATH -Destination $CopyPathM -Force

        $XMLA= Get-Content -Path $CopyPathM | %{$i = 1} { new-object psobject -prop @{LineNum=$i;Text=$_}; $i++}
        Return $XMLA
    
    }
    
    $DTSX1 = GenerateXML -DTSXPATH $DTSX1Path -Cnt $Counter 
    
    $Counter = $Counter + 1 
    
    $DTSX2 = GenerateXML -DTSXPATH $DTSX2Path -Cnt $Counter
    
    Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)"
    
    $Difference = Compare-Object $DTSX1 $DTSX2 -Property Text -PassThru 
    
    $Result_File1 = $Difference | Where-Object -Property SideIndicator -EQ "<=" 
    $Result_File2 = $Difference | Where-Object -Property SideIndicator -EQ "=>"

 

    $ResultPath = $DTSX1Path.Substring(0, $DTSX1Path.lastIndexOf('\'))

 

    IF($ResultOutput -eq 'Console')
    {
        Write-Host 'Changes / Addtions in Original DTSX'
        $Result_File1 | Select-Object LineNum,Text

 

        Write-Host 'Changes / Addtions in Changed DTSX'
        $Result_File2 | Select-Object LineNum,Text
    }
    
    Else

 

    {

 

        $Result1Path = $ResultPath + '\' + 'Results_Changed_Or_Additional_Components_in_OriginalDTSX.txt'
        $Result2Path = $ResultPath + '\' + 'Results_Changed_Or_Additional_Components_in_ChangedDTSX.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 DTSX for Original and Changed are also created with results on the same path as that of Original DTSX'
        Write-Verbose "Results for Changes / Addtion in Original DTSX is placed on : $($Result1Path)"
        Write-Verbose "Results for Changes / Addtion in Changed DTSX is placed on : $($Result2Path)"

 

    }
    
    

 

    Write-Verbose 'Process Complete'

 


    Write-Verbose "Time Elapsed in Seconds : $($StopWatch.Elapsed)"
}


Export-ModuleMember -Function Compare-DTSX