What I'm trying to do is compare the data from two pscustomobject arrays, Then have the data that doesnt matches saved into an array. That array will then be exported to a CSV file. This is what i have.
function DataCompare {
$NotMatch = @()
#Compares the two arrays together and saves the ones that are different in the InfoFusion into ResultsFromFusion
$ResultsFromFusion = Compare-Object -ReferenceObject $Global:InfoFusion -DifferenceObject $Global:InfoPPMS -Property programmeLevel1, programmeLevel2, programmeLevel3, programmeLevel4 -PassThru | Where-Object SideIndicator -eq '<='
#Loops through the fusion results that dont match
ForEach ($Project in $ResultsFromFusion){
#Gets the matching data from the PPMS data so the NotMatch csv has both the fusion and ppms data
$PPMSFromDiff = $Global:InfoPPMS -match $Project.ProjectNumber
$NotMatch += @([pscustomobject]@{ProjectId = $($Project.ProjectId);
ProjectNumber = $($Project.ProjectNumber);
programmeLevelFusion1 = $($Project.programmeLevel1);
programmeLevelPPMS1 = $($PPMSFromDiff.programmeLevel1);
programmeLevelFusion2 = $($Project.programmeLevel2);
programmeLevelPPMS2 = $($PPMSFromDiff.programmeLevel2);
programmeLevelFusion3 = $($Project.programmeLevel3);
programmeLevelPPMS3 = $($PPMSFromDiff.programmeLevel3);
programmeLevelFusion4 = $($Project.programmeLevel4);
programmeLevelPPMS4 = $($PPMSFromDiff.programmeLevel4)})
}#Loop End
$NotMatch | export-csv -Path $NotMatchPath -NoTypeInformation -Encoding utf8
}#Function End
However, when doing this the CSV saves with System.Object[] in some of the cells and its switching out charaters like "-" with "?" even though i added encoding utf8 for it not to do this. Can anyone help with this.
Edit: This is what the two arrays that ar ebeing compared look like.
$Global:InfoPPMS += @([pscustomobject]@{ProjectId = $($Project.ProjectId);
ProjectNumber = $($Project.ProjectNumber);
programmeLevel1 = $($programmeLevel1);
programmeLevel2 = $($programmeLevel2);
programmeLevel3 = $($programmeLevel3);
programmeLevel4 = $($programmeLevel4)})
$Global:InfoFusion += @([pscustomobject]@{ProjectId = $($Project.ProjectId);
ProjectNumber = $($Project.ProjectNumber);
programmeLevel1 = $($RestMethID.programmeLevel1);
programmeLevel2 = $($RestMethID.programmeLevel2);
programmeLevel3 = $($RestMethID.programmeLevel3);
programmeLevel4 = $($RestMethID.programmeLevel4)})
this is how they look.