PowerShell を使用して、コンピューターでポートが開いているかどうかを確認します。8 台の Windows 2008 R2 マシンを取得し、次のスクリプトを実行します。
$localhost = get-content env:computername
foreach($port in get-content "\\computer1\txtfiles\ports.txt")
{
foreach ($hostname in get-content "\\compiuter1\txtfiles\servers.txt")
{
try {
$sock = new-object System.Net.Sockets.Socket -ArgumentList $([System.Net.Sockets.AddressFamily]::InterNetwork),$([System.Net.Sockets.SocketType]::Stream),$([System.Net.Sockets.ProtocolType]::Tcp)
$sock.Connect($hostname,$Port)
$output = $localhost+","+$hostname+","+$port+","+$sock.Connected
$output
$sock.Close()
}
catch {
$output = $localhost+","+$hostname+","+$port+","+$sock.Connected
$output
}
}
}
そして、次を使用して、computer1 から 8 台のコンピューターでこのスクリプトを実行します。
Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1
最初のコンピューター (computer1- スクリプトを実行するマシン) では出力が得られましたが、computer2 では次のようになりました。
Cannot find path '\\computer1\txtfiles' because it does not exist.
+ CategoryInfo : ObjectNotFound: (\\computer1\txt
files:String) [Set-Location], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
Powershell がネットワーク共有を認識しないのはなぜですか? どうすれば修正できますか?