To address the reason you’re getting the error, you’re missing the closing parenthesis ‘)’ for the ForEach() method call.
These errors are easier to spot if you indent your code and use an editor with highlighting such as VSCode (which will also automatically insert closing brackets). Also consider adding comments at closing brackets.
For every line in $serverone, you’re checking if $serverone contains ‘SampleFile’. The correct syntax for what you’re trying to do is:
$sampleone.ForEach({$_.Contains('SampleFile)})
In all honesty though, that’s horrible code. Contains is meant for checking for the existence of objects in collections, it’s not really meant for comparing bits of Strings. As Olaf suggests, use native PowerShell for this.
Select-String -Path .\sample.txt -Pattern 'SampleFile' | Select -ExpandProperty Line