0

I have a list of servers to which I should have access. I know that to some of them I have not. I want to check access to each server and list only that ones to which I do not have access. To do that I created script which for each server use test-netconnection function to check if I am able to connect and then I use if statement to write server name to the file if the test was not successful. Unfortunately seems that if does not work as I expected.

Could you please advice what I am doing wrong with the example below?

I run the below script

$test_result.TcpTestSucceeded


   if($test_result.TcpTestSucceeded -eq 'False' )
    {
        Write-Output 'a'
    }
    else
        {
        Write-Output 'b'
    }

and I have the below result

enter image description here

As you can see even-though value is true powershell choose option a, while I would expect that option b should be displayed.

  • 3
    Does this answer your question? [Why does 'true' equal $true](https://stackoverflow.com/questions/37345334/why-does-true-equal-true) which also explains opposite: why **`$true` *not* equals `'true'`** (or **`$false` *not* equals `'false'`**). – iRon Aug 27 '21 at 17:14

1 Answers1

1

$test_result.TcpTestSucceeded

if($test_result.TcpTestSucceeded -eq $False ) { Write-Output 'a' } else { Write-Output 'b' }

Try This

Nayshr
  • 26
  • 3