我使用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
}
}
}
我使用运行8的计算机上运行此脚本从电脑1:
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看不到网络共享?我该如何解决它?
这两个地址应该是不同的? '\\ computer1 \ txtfiles'!= '\\ compiuter1 \ txtfiles' – JohnL