I have been trying numerous functions in Powershell including Comparison Object, for each function but with no success.
This is what I want to do.
I have two files named as File 1 and File 2. Within File 1, I have a line like this.
In File 2, I have this.
So I want to compare the value of ContractGroups from File 1 to the value of ContractGroups in file 2. If matched, I want to add an outcome to the file.
The difficulty I am having is that I can set up a variable to get the content for matching. But when comparing, I want to only take into account of ContractGroups for a match. So as soon as file 2 is scanned, then I want to see if the value of ContractGroups matches to file 1.
I think for comparison, I just need to find a way of scanning the line that contains Name="ContractGroups" Value from file 1 and then reading its value (CC) and then scanning file 2 to first see if has a line matches Name="ContractGroups" Value and if yes, and then does the value of it is the same (CC) as file one? If yes, then just write that "Matched" to a blank file.
It would be helpful if you shed light on this. Sorry as I am new on PS.
What I have tried:
I have tried this.
$file1 = Get-Content "C:\Users\Altunokc\Desktop\Guardian\NotUsed\20200513 Environment parameters\EnvironmentParameters_ICE_EU_PROD.xml"
$file2 = Get-Content "C:\Users\Altunokc\Desktop\inetpub\wwwroot\EU\Guardian\Website\appSettings.config"
$pattern = $file1| %{$_ -MATCH '.Name="ContractGroups" Value'}
$result = "C:\Users\Altunokc\Desktop\Differentdd.txt"
$file1 | foreach { $pattern = $file2 -match $_
if ( $match ) { $match | Out-File -Force $result -Append }
}
and this way
if(Compare-Object -ReferenceObject $(Get-Content $file2 ) -DifferenceObject $(Get-Content $file1 ) | %{$_ -MATCH '.Name="ContractGroups" Value'} -SimpleMatch|
Out-File -FilePath C:\Users\Altunokc\Desktop\Different.txt)
{"match"}
Else {"No "}
No luck.