Objective: Compare the strings stored in $a
with strings stored in $b
. If strings exist in $b
that do not exist in $a
, display those.
I'm running the following to search text files for certain information:
$a = Select-String -Path *.txt "<string>"
This returns lines containing the names of the text files (which are named after the servers they come from), the line number the string is found on, and the string itself. It stores it in the
$a
variable.I run the following to store a list of server names in variable
$b
:$b = Get-Content servers.txt
I run the following to compare the contents of
$a
with$b
, and tell me if there are any in the list in$b
that are not contained in$a
:$b | Where-Object {$a -NotMatch $_}
I'm clearly doing something wrong, because this simply displays the contents of
$a
. Any ideas of how I can accomplish my objective?