I have a list of Contract numbers in a text file.
185
166
504
506
507
510
509
I have servername like SERVER999AUTO1. I need to check if the number 999 present in the file. if present then, no operation else we have to perform certain operation.
I tried below, but for each contract it is printing the else value
$file = Get-Content "C:\list.txt"
$containsWord = $file | %{$_ -match "SERVER999AUTO1"}
if ($containsWord -contains $true) {
Write-Host "There is!"
} else {
Write-Host "There ins't!"
}
Please let me know on this.
"SERVER999AUTO1", which it won't match it. In other words, your precedence is wrong when it's supposed to be:"SERVER999AUTO1" -match $_. Change it to that and it should work.