ASDatabaseComparator.psm1

<#
     .SYNOPSIS
         This command will compare the 2 ASDatabase(ASPAC) Files of Analysis service 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 ASDatabase 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 OriginalASPAC
         The second set contains the Objects that are either Extra or Changed from ChangedASPAC
         The Results sometimes might not be straight forward, as a result when File Option is chosen , the XML's for both the ASPACs 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 OriginalASDatabasePath
     Accepts the path where First / Original ASDatabase is placed
 
  
 
     .PARAMETER ChangedASDatabasePath
     Accepts the path where Second / Changed ASDatabase is placed.
 
  
 
     .PARAMETER ResultOutput
     Accepts either Console or File, to determine where result is to be shown / placed.
 
  
 
     .EXAMPLE
      Compare-ASDatabase -OriginalASDatabasePath 'C:\Users\SSAS\AdventureWorksDev.asdatabase' -ChangedASDatabasePath 'C:\Users\SSAS\AdventureWorksTest.asdatabase' -ResultOutput Console -Verbose
      Compare-ASDatabase -OriginalASDatabasePath 'C:\Users\SSAS\AdventureWorksDev.asdatabase' -ChangedASDatabasePath 'C:\Users\SSAS\AdventureWorksTest.asdatabase' -ResultOutput File -Verbose
 
  
 
#>


Function Compare-ASDatabase
{

 

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

 

    )

 

    $Stopwatch = [system.diagnostics.stopwatch]::StartNew()
    
    Write-Verbose 'Starting Process of Comparing ASDatabase'
    
    $Counter = 1
    
    Write-Verbose 'Reading ASDatabase Files'
    
    $ASPAC1Path = $OriginalASDatabasePath
    $ASPAC2Path = $ChangedASDatabasePath

 

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

 

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

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

 

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

 

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

 

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

 

    {

 

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

 

    }
    
    

 

    Write-Verbose 'Process Complete'

 


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


Export-ModuleMember -Function Compare-ASDatabase