【发布时间】:2014-12-19 18:18:52
【问题描述】:
我正在编写一个 powershell 脚本来查找未在我们的服务器上运行或指向另一台服务器的网站。我正在从一个文件中获取所有网站名称,并使用它来仅查找那些不在我们服务器上运行的网站。我正在尝试使用以下脚本,但出现错误。
一如既往,非常感谢您的帮助或建议。
$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
}
}
以下是我得到的错误:
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
【问题讨论】:
-
别让我们悬念:有什么错误?
-
下面是我收到异常调用“GetHostAddresses”与“1”参数的错误:“没有这样的主机是已知的”在 C:\test1.ps1:3 char:50 + $地址 = [System.Net.Dns]::GetHostAddresses
-
我的工作正常。这在您的最终失败时是哪个
$server值?
标签: powershell nslookup