$inventory = Import-Csv "E:\MonitoringScripts\HealthCheck\PatStat_Pshell\inventory.csv"
foreach ($line in $inventory) {
$server_name = $($line.servername)
$port_number = $($line.port)
$resolved_true = [System.Net.Dns]::GetHostAddresses("$server_name")
#Write-Host $resolved_true
if ($resolved_true) {
#Write-Host $server_name
Write-Host 'the host is resolving'
} else {
Write-Host 'Not found in DNS'
}
}
В приведенном выше коде, как я могу избежать отображения приведенного ниже содержимого в командной строке, если в файле инвентаризации есть хост, который не разрешает DNS?
Exception calling "GetHostAddresses" with "1" argument(s): "No such host is
known"
At E:\MonitoringScripts\HealthCheck\PatStat_Pshell\patrol.ps1:9 char:2
+ $resolved_true = [System.Net.Dns]::GetHostAddresses("$server_name")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SocketException
Not found in DNS
the host is resolving
Iпросто хочу увидеть:
Not found in DNS
или
the host is resolving