windows - Else condition does not work in powershell with GetHostEntry -


i have simple script resolves ip's hostnames. have file of ip addresses in flows.txt , resolving ip's hostnames. problem if there ip not resolvable, script not "$ip not found" have defined to. instead, outputs ip address had listed in flows.txt file. i'd that particular ip address not resolvable or "$ip n/a" if can find error, please correct me if possible. thanks!

$flows = get-content c:\scripts\flows.txt $resultlist = @()  foreach ($ip in $flows) {      $result = $null      $erroractionpreference = "silentlycontinue"      $result = [system.net.dns]::gethostentry($ip)       if ($result)      {           $resultlist += [string]$result.hostname      }       else      {           $resultlist += "$ip - no hostnamefound"      } }  $resultlist | out-file c:\scripts\output.txt 


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -