I isolated some code and i have an unexpected behavior.
code:
$objects = @(
[pscustomobject]@{server="google.com"; some_other_props='some_str'},
[pscustomobject]@{some_other_props='some_str'},
[pscustomobject]@{server='google.com'; some_other_props='some_str'}
)
$objects | % {
try{
$result = Test-Connection $_.server
}catch [System.Management.Automation.ParameterBindingException] {
Write-Host "no server to ping"
}
if($result){
Write-Host ok
}
}
expected output:
ok
no server to ping
ok
real ouput:
ok
no server to ping
ok
ok
What am i doing wrong here? from where is the 3rd ok coming??
if($result) ...That should go inside thetryblock.