PowerShell Compare-Object misbehaving or objects not compatible for comparison?
I am trying to compare the names of noteproperty items in two different variables created by different means
The first is a list of columns in an SQL Server database, the second comes from ConvertFrom-Json
I have tried to make the objects compatible for comparison with each other by using several different techniques but every method i try fails.
Below is the best working example of code i have been able to come up with but the results it gives are not correct.
In the below example, just before the compare-object command the variables equal:
As you can see timestamp exsits on both sides of the compare yet the result does not agree. event_id exsits on one side without the other yet is not listed. event is correct as it appears on both.
Can anyone explain what might be happening and how to get the required result?
My ultimate goal is to check a the database for columns that will require adding before a object derived from ConvertFrom-Json is added to a row. Every noteproperty obviously has to have a place in the database and so to eliminate errors i need to create those columns in advance. This part of the script is meant to compare what is needed and what is there already and therefore creating a list of what we don't have - this will get passed to an SQL ALTER table command to add the columns.
Unless you are comparing arrays of simple objects (like strings), you need to specify which property (or properties) you want to compare with the Compare-Object -Property parameter. So in this case it looks like you would specify -Property Name.
Stuart Dryden
ASKER
Hi footecch,
Thanks for your help time and time again. I tried the -Property Name option before but as the result was even worse than what i wrote above i moved past it.