私はpowershellを使用して、自分のコンピュータでポートが開かれているかどうかを調べます。私は8つの窓2008 R2マシンを持って、私は次のスクリプトを実行します。Powershellはネットワーク共有にアクセスできない
$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
}
}
}
をそして私が使用してコンピュータ1から8コンピュータでこのスクリプトを実行します。
Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1
を最初のコンピュータで(私は、スクリプトを実行するマシンをcomputer1-)私は出力を得たが、私が持ってコンピューター上:
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はネットワーク共有を見ませんか?どうすれば修正できますか?
2つのアドレスは異なるはずですか? '\\ computer1 \ txtfiles'!= ' \\ compiuter1 \ txtfiles' – JohnL