According to my last question Compare two Files I finally managed to get all to work inside my .bat. Thanks again for all your support.
However, as I find out today my supervisor is using Powershell in Version 2 instead of 5.1 than I do. The problem now is that the -Raw paramterer of this code:
$target = Get-Content "C:/pbr_tmp/PBreport/trc/TlsTrace.prn" -Raw
I changed this to:
$target = [System.IO.File]::ReadAllText("C:/pbr_tmp/PBreport/trc/TlsTrace.prn")
Unfortunately, the results are incorrect and I receive following error:
GetEnumerator : Fehler beim Aufrufen der Methode, da [System.Collections.DictionaryEntry] keine Methode mit dem Namen "GetEnumerator" enthält.
Does anyone know if there is something in the complete code snippet which can cause this?
$data = Import-Csv "C:/trc/ModulID.txt" -Delimiter ";" -Header ID,Term
$target = [System.IO.File]::ReadAllText("C:/pbr_tmp/PBreport/trc/TlsTrace.prn")
$counts = @{}
foreach ($term in $data.Term) {
$term = $term + " "
$index = -1
$count = 0
do {
$index = $target.IndexOf($term, $index + 1)
if ($index -gt -1) { $count++ } else { break; }
} while ($true);
if ($count -gt 0) {$counts[$term] = $count}
}
$counts = $counts.GetEnumerator() | sort name
$counts.GetEnumerator() |ForEach-Object {$_.Key, $_.Value -join '' } |Set-Content C:/pbr_tmp/PBreport/trace_results.txt
For example,
$counts = $counts.GetEnumerator() | sort name
Throws no exception.