Hi everyone, I've been trying get my head around this and can't work it out.
I have two CSV files which I would like to compare. The problem is the lines are ordered differently in each in file so I'm not sure how to compare the correct lines. Sometimes certain lines won't exist so I figured reordering the file first may not work.
For example:
CSV1 (assigned usage)
Name,RAM,CPU,
Geoff.5GB,2,
Bob,2GB,2,
Fred,2GB,2,
Paul,2GB,1,
CSV2 (actual usage)
Name,RAM,CPU,
Bob,2GB,2,
Fred,4GB,2,
Geoff,10GB,2,
I need to compare these two files and report on who is using more RAM (and Ideally CPU) than they are assigned. In the example above, Geoff is using 10GB of RAM in CSV2 but is only allocated 5GB ins CSV1.
I was trying to loop through the first CSV but I'm not sure how to compare to the correct line in CSV2.
I have no idea what I'm doing but I started with:
$file1 = import-csv "C:\CSV1.csv"
$file2 = import-csv "C:\CSV2.csv"
foreach ($line in $file1) {
if ( ($file2.Name -eq $line.Name) -and ($line.'RAM' -gt $file2.RAM)) { write-host "Good" }
else { write-host "Bad"}
}
Any ideas on how I can achieve this?