Questions tagged [compareobject]

Usually refers to object comparison in object oriented languages.

Typical cases compare:

  • Ojects values.
  • Object references.
  • Object types.
99 questions
12
votes
3 answers

PowerShell: Function doesn't have proper return value

I wrote a powershell script to compare the content of two folders: $Dir1 ="d:\TEMP\Dir1" $Dir2 ="d:\TEMP\Dir2" function Test-Diff($Dir1, $Dir2) { $fileList1 = Get-ChildItem $Dir1 -Recurse | Where-Object {!$_.PsIsContainer} | Get-Item |…
Mattia72
  • 825
  • 1
  • 8
  • 23
9
votes
2 answers

compare-object left or right side only

Quick Question Is there a better (i.e. more efficient / more concise) way to do this? compare-object $a $b | ?{$_.SideIndicator -eq '<='} Detail Compare-Object gives paramenters -excludeDifferent and -includeEqual to allow you to amend which…
JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
6
votes
2 answers

Powershell Compare-Object Format Output

Here is the script that I wrote: function Compare { $file1 = Read-Host "Please enter the path of the first file you would like to compare" $file2 = Read-Host "Please enter the path of the second file you would like to compare" $outFile…
BRBT
  • 1,467
  • 8
  • 28
  • 48
5
votes
1 answer

Using PowerShell to find the differences in strings

So I'm playing around with Compare-Object, and it works fine for comparing files. But what about just strings? Is there a way to find the difference between strings? CompareTo() is good about reporting that there is a difference, but not what the…
James Brown
  • 327
  • 2
  • 11
  • 21
3
votes
2 answers

How to compare two objects in Java 8

Lets take an example you have two employee object having same values as follows. Employee employee1 = new Employee(1001, "Sam", 20000); Employee employee2 = new Employee(1001, "Sam", 20000); if(doCompareEmployees(employee1, employee2)){ …
Sabarish.K
  • 109
  • 1
  • 2
  • 7
3
votes
4 answers

Compare two CSV and export only a list of names that don't exist in both

I have 2 CSV files with user names. I want to export just the names of users who don't exist in both files. The code I have now: $file1 = import-csv -Path "C:\ps\output\adusers.csv" $file2 = import-csv -Path "C:\ps\output\users.csv" Compare-Object…
Provo
  • 31
  • 1
  • 2
2
votes
1 answer

PowerShell Compare-Object and Export-Csv exporting wrong data

Problem I have two CSV files, file A and file B. Both files contain the same header. The files contain information about quotes and orders. File A was created first, at let’s say 10:00 AM. File B was created at 11:00 AM. That’s when the status…
joostvdlinden
  • 55
  • 1
  • 5
2
votes
1 answer

PowerShell Compare-Object to produce change report file

I've looked at numerous examples and have made headway in producing a change report. But, I'm stuck in one area. Here's the scenario... File 1 CSV file sample data ID,Name,Location,Gender 1,Peter,USA,Male 2,Paul,UK,Male 3,Mary,PI,Female File 2 CSV…
2
votes
2 answers

PowerShell - Was A File Created For Each Hour?

I'm attempting to create a PowerShell script that will run once every morning (via Task Scheduler) and alert someone (via Direct Send (I know how to do this and will implement said feature later)) if a file wasn't created during each hour for the…
Mentat
  • 70
  • 1
  • 8
2
votes
1 answer

How to compare two tables with one column that is slightly different in PowerShell?

I would like to compare the version info of files from two different directories. I could do this: $files1 = (Get-Item "$path1\*.dll").VersionInfo $files2 = (Get-Item "$path2\*.dll").VersionInfo compare-object $files1 $files2 But then I get…
Adrian
  • 10,246
  • 4
  • 44
  • 110
2
votes
2 answers

Import-Csv data parse to array

I have a CSV file which contains multiline in some cells. I will use this data to compare the value got it from powershell. This returns differences between the object, however the value is the same. Expected Results should return nothing because…
2
votes
3 answers

Compare two text files and write the differences to text file

I want to compare 2 text files and output the difference in another text file. $Location = "c:\temp\z.txt" compare-object (get-content c:\temp\hostname_old.txt) (get-content c:\temp\hostname_new.txt) | format-list | Out-File…
Arbelac
  • 1,698
  • 6
  • 37
  • 90
2
votes
4 answers

Replace Arrows for SideIndicator in Compare-Object

Can I change the output for SideIndicators as a result of Compare-Object to something more user friendly for standard users? I have a script that compares the folder of a 2017 version of our software and the current 2018 version. $var1 =…
ATKiwi
  • 87
  • 1
  • 7
2
votes
1 answer

Powershell compare-object output 1 line per item

I am attempting to put the output of compare-object. I am new to Powershell and unfortunately don't know the ins and outs yet. My command is as follows: Compare-Object -referenceObject $(Get-Content "c:\temp\mek\123-first.txt") -differenceObject…
oliverkiss.com
  • 47
  • 1
  • 10
2
votes
1 answer

Comparing files based on version number and some criterias and Formatting the output

I am comparing dll files based on size, last write time and version number using Compare-object in Powershell. These files are stored on remote servers. I am getting the result. The only problem is how to get the value of the version number from the…
1
2 3 4 5 6 7