1

サーバーで実行されていないか、別のサーバーを指している Web サイトを見つけるために、powershell スクリプトに取り組んでいます。ファイルからすべての Web サイト名を取得し、それを使用して、サーバーで実行されていない Web サイトのみを検索しています。以下のスクリプトを使用しようとしていますが、エラーが発生します。

いつものように、ヘルプやアドバイスをいただければ幸いです。

$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
4

1 に答える 1

2

例外をトラップするだけです:

try {
    $addresses = [System.Net.Dns]::GetHostAddresses($server);
}
catch {
    $addresses = [IPAddress]'0.0.0.0';
}
于 2014-12-19T20:25:48.640 に答える