Does this help? Note the use of import-csv.
https://devblogs.microsoft.com/scripting/powertip-get-row-from-csv-file-based-on-value/
$servers = Get-Content C:\TEMP\Servers.txt
"Here are the servers."
$servers
""
$raw = Get-Content C:\TEMP\Test.csv
"Here is the raw csv."
$raw
""
$collected = Import-Csv C:\TEMP\Test.csv
"Here is the imported csv."
$collected
""
foreach ($server in $servers) {
"Looking for $server"
if ($collected.Where({$PSItem.PSComputername -eq $server}) ) {
"$server information already collected."
} else {
"$server information NOT yet collected."
}
""
}
Some test data produces this and finds test10.
Here are the servers.
localhost
xxxxxxxxx
Test10
Here is the raw csv.
"PSComputername","SomeField","AnotherField"
"AAAAA","11111","aaaaaaa"
"Test10","22222","bbbbb"
"ZZZZZ","33333","ccccc"
Here is the imported csv.
PSComputername SomeField AnotherField
-------------- --------- ------------
AAAAA 11111 aaaaaaa
Test10 22222 bbbbb
ZZZZZ 33333 ccccc
Looking for localhost
localhost information NOT yet collected.
Looking for xxxxxxxxx
xxxxxxxxx information NOT yet collected.
Looking for Test10
Test10 information already collected.
Update: to use the -IN operator, the IF statement should be:
if ($server -in ($collected).pscomputername) {