Supress 'true' to screen when if(conditional) resolves to true

My PseudoCode:

if (conditional) {

… ok to screen

… ok to screen

}

“True” being displayed to screen after {… stuff} when the enclosing f (conditional) has returned true

That won’t normally happen with most commands. What’s your actual code look like? An if statement on its own doesn’t have any output.

CODE:

$SBDAT = Get-Content C:\Users\mayres\Desktop\U14187SB_testing_2.DAT
foreach ($line in $SBDAT) {
$count++
'processing line '  + $count
if (select-string  -pattern "SB140" -InputObject $line  ) {
'found a SB140 at line ' + $count
# $errors ++
# $errorentry = $line
write-output ('Lines ' + $count +'and ' + ($count+1) + ' are '+ $errorentry)
$foreach.MoveNext()
$line + $foreach.current
$count ++
pause
}
}
SCREEN OUTPUT:
processing line 4
processing line 5
processing line 6
processing line 7
processing line 8
processing line 9
found a SB140 at line 9
Lines 9and 10 are

True

SB140187Cha567429592S19360110F 1 95490XXXX50000 31954XXXXXX H50081000000000063000000000246000000001Y0 N NNNNNNNNNNNNNNNNNNNNYNDoree Chase XXXXXXXXXXXXXXXXXXXXXX
SB141187Cha567429592S19360110F 1 95490XXXX50000 31954XXXXXX H50081000000000063000000000246000000001Y0 N NNNNNNNNNNNNNNNNNNNNYNDoree Chase XXXXXXXXXXXXXXXXXXXXXX

Press Enter to continue...:

// The ‘True’ output to screen after ‘Lines 9 and 10 are’ seems to be coming from a Boolean return of the IF (condition) which when true returns the following correct 2 record lines//

$foreach is an IEnumerator-type object, and its MoveNext() method is explained here: https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerator.movenext?view=netframework-4.8

Essentially, when you call it, it always returns a boolean value. If you don’t care about that value, you’ll need to tell PS to discard it by either the $null = or > $null methods, e.g., $null = $foreach.MoveNext() or $foreach.MoveNext() > $null

Ah, the true response is not from the IF conditional but the enumerators.movenext() method. Never thought of that, and that is PS’s inheritance of MS’s types and objects, opening a whole new universe.

 

Thanks