Modul_Cleoni_Compare.psm1

Function func_ComparePackage($PID_Path, $Excelpath1, $Excelpath2) {
        function Module-Install() { 
            ###################################################
            If (!(Get-InstalledModule ImportExcel -ErrorAction SilentlyContinue)) {
                Install-Module -Name ImportExcel -Confirm:$false -AllowClobber -Force | Out-Null
            }
            Import-Module ImportExcel -Scope Global | Out-Null
            ###################################################
        }
        Function Search-Different($Excellist1, $Excellist2, $Categorie) {

            $DiffList = @()
            Foreach ($Entry1 in $Excellist1) {
                $AvailMembers = ($Entry1 | Get-Member -MemberType NoteProperty).Name
                
                $Keyword = 'Hash'

                $qid = $($Entry1 | Select-Object -ExpandProperty $Keyword)
                $Entry2 = $Excellist2 | Where-Object { $_.$Keyword -eq $qid }

                If ($AvailMembers -contains 'displayName')
                {
                 $Name = $Entry1.Displayname
                }
                Else
                {
                 $Name = $Entry1.Name 
                }
   
                Foreach ($AvailMember in $AvailMembers)
                {  
                 $Prob1 = $Entry1 | Select-Object -ExpandProperty $AvailMember
                 $Prob2 = $Entry2 | Select-Object -ExpandProperty $AvailMember
                 
                 If ($Prob1.length -eq 0) {$Prob1 = 'nA'}
                 If ($Prob2.length -eq 0) {$Prob2 = 'nA'}

                 $result = [bool](Compare-Object -ReferenceObject $Prob1 -DifferenceObject $Prob2)

                 #Workaround
                 If ($Categorie -eq 'Settings Catalog' -or $Categorie -eq 'DeviceConfigurations') { $Property = $Entry1.Property.Trim() }
                 else { $Property = $AvailMember.Trim() }

                 If ($result) {
                     $Line = '' | Select Categorie, Name, Property, OldValue, NewValue
                     $Line.Categorie = $Categorie.Trim()
                     $Line.Name = $Name.Trim()
                     $Line.Property = $Property
                     $Line.OldValue = $Prob1
                     $Line.NewValue = $Prob2
                     $DiffList += $Line
                 }  
                }
            }
            return $DiffList
        }
   
        If (!(Test-Path -Path $PID_Path)) { New-Item -Path $PID_Path -ItemType Directory | out-null }
        $PID | Out-File -FilePath "$PID_Path\PID.txt" -Encoding utf8 -Force | out-null
        
        Module-Install

        $AllWorksheetName = @()
        $AllWorksheetName1 = (Get-ExcelSheetInfo $Excelpath1).Name
        $AllWorksheetName2 = (Get-ExcelSheetInfo $Excelpath2).Name
   
        foreach ($Entry in $AllWorksheetName1) {
            If ($Entry -in $AllWorksheetName2) {
                $AllWorksheetName += $Entry
            }
        }
     
        $Results = @()
        foreach ($Categorie in $AllWorksheetName) {  
            $Excel1_Apps = Import-Excel -Path $Excelpath1 -WorksheetName $Categorie
            $Excel2_Apps = Import-Excel -Path $Excelpath2 -WorksheetName $Categorie
            $Results += Search-Different -Excellist1 $Excel1_Apps -Excellist2 $Excel2_Apps -Categorie $Categorie
            [System.Windows.Forms.Application]::DoEvents()
        }

        return $Results
    }