I am comparing two csv files and I noticed it was reading the line per line, which I did not want. I have figured out how to use the select -expand property in the compare-object import to help it find the difference in logonid vs doing line by line. MY issue is once a logon id is found I want to output all the other colums that are associated with the logonid to my log file. How can I do that. Below is a sample and it works if I allow a line by line but I need to filter by logon id and when found output the whole row of info for that user How can I accomplish this. example of my input file. logonid name displayname and so on.
importFile1 = Import-Csv -Path $file1
$importFile2 = Import-Csv -Path $file2
$compareObj = compare-Object -ReferenceObject (import-csv -Path $file1 | select -expandProperty logonid) -DifferenceObject (Import-Csv -Path $file2 | select -expandProperty logonid)
foreach($conflict in $compareobj){
Write-Host $conflict
if($_.sideindicator -eq "=>"){
$ChangeFile = $file2Path
$note = "Looks Like Addition to the Group has occurred"
}
else{
$ChangeFile = $file1Path
$note = "Looks Like an Object was removed from this group"
}
New-Object -TypeName PSCustomObject -Property @{
LogonID = $conflict.inputobject.logonid
Name = $conflict.inputobject.name
DisplayName = $conflict.inputobject.displayname
AccountDisabled = $conflict.inputobject.AccountDisabled
GroupName = $conflict.inputobject.groupname
NestedMember = $conflict.inputobject.nestedmember
GroupEmpty = $conflict.inputobject.GroupEmpty
ParentGroup = $conflict.inputobject.ParentGroup
ConflictFile = $ChangeFile
Note = $note
} | select-object LogonID,Name,Displayname,AccountDisabled,GroupName,NestedMember,GroupEmpty,ParentGroup,ConFlictFile,Note | Export-Csv $LogFile -Append -NoTypeInformation
}
}