I currently have two arrays full of names. One contains data read in from a txt file, and one read in from a CSV file. I'm trying to return lists of names that appear on both lists, and that only appear on individual lists. For the CSV file, PowerShell originally wanted to place "Name="
in front of each item, but I used $formattedName = $csvFile -replace "Name=",""
to get rid of it. I should also mention that Name
is the header for that column. At this point, if I call the variable $formattedName
, it returns the list of names without Name=
in front of them (aka exactly how the txt if formatted to compare).
Now when trying to use Compare-Object
, I'm running into an issue. My code reads:
Compare-Object -ReferenceObject $txtFile -DifferenceObject $formattedName -IncludeEqual
Now, when running this command, PowerShell still places Name=
in front of each item for the CSV file, regardless of the fact that I just formatted it to not do that. My end result is two lists, one containing all items from the txt file and one containing all items from the CSV file. There are no two matching values because Steven
is not the same as Name=Steven
. An example of the output is:
Steven =>
Name=Steven <=
How can I go about fixing this? Am I using this properly?