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
Post a Comment