I am working on a powershell script to find websites that either do not work on our server or point to another server. I extract all the site names from the file and use it to find only those sites that do not work on our server. I am trying to use the below script, but getting an error.
As always, both help or advice would be greatly appreciated.
$servers = get-content "path_to_the_file"
foreach ($server in $servers) {
$addresses = [System.Net.Dns]::GetHostAddresses($server)
foreach($a in $addresses) {
"{0},{1}" -f $server, $a.IPAddressToString
}
}
The following is the error:
Exception calling "GetHostAddresses" with "1" argument(s): "No such host is known" At
C:\test1.ps1:3 char:50 + $addresses = [System.Net.Dns]::GetHostAddresses <<<< ($server) +
CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId :
DotNetMethodException
source
share