Powershell 无法访问网络共享

发布于 2024-11-29 13:45:23 字数 1286 浏览 0 评论 0 原文

我使用 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

}
}

}

并且我使用以下命令在计算机 1 的 8 台计算机上运行此脚本:

Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1

在第一台计算机(计算机 1-我执行脚本的计算机)上,我得到了输出,但在我得到的计算机2:

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看不到网络共享?我该如何修复它?

I use powershell to check if the ports are opened on my computers. I got 8 windows 2008 R2 machines and I run the following script :

$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

}
}

}

And I run this script on the 8 computer from computer1 using :

Invoke-Command -ComputerName computer1,computer2 -FilePath F:\scripts\port-test.ps1

On the first computer (computer1- the machine that I execute the script from ) I got an output but on the computer2 I got :

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

Why isn't Powershell seeing network share? How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮萍、无处依 2024-12-06 13:45:23

听起来像是双跳问题 - http://blogs.technet.com/b/askds/archive/2008/06/13/understanding-kerberos-double-hop.aspx - 基本上,您正在远程连接到一台计算机,然后尝试访问另一台计算机。您的 kerberos 令牌被视为无效,因为原始令牌和目标令牌之间有一台机器。

您使用什么操作系统(源操作系统和目标操作系统与 CredSSP 相关)?如果一直是 Windows 2008 或 Windows 7 并且问题是双跳,您可以使用 CredSSP 来避免它 - http://www.ravichaganti.com/blog/?p=1230

Sounds like the double hop issue - http://blogs.technet.com/b/askds/archive/2008/06/13/understanding-kerberos-double-hop.aspx - basically you are remoting to one machine and then trying to access another machine. your kerberos token is seen as invalid as there's a machine in between the original and the destination.

What OS are you using (the source and the destination OS is relevant for CredSSP)? If it is Windows 2008 or Windows 7 all the way through and the issue is double hop you may be able to us CredSSP to avoid it - http://www.ravichaganti.com/blog/?p=1230

我们的影子 2024-12-06 13:45:23

如果不是访问控制问题,请考虑我在通过服务器复制文件时遇到的类似问题并出现此错误:

无法找到路径“\\computer1\d$\path”,因为它不存在。

在文件名前面添加 Microsoft.PowerShell.Core\FileSystem:: 后即可工作:

copy-item "Microsoft.PowerShell.Core\FileSystem::\\computer1\d$\path\installer.msi" "Microsoft.PowerShell.Core\FileSystem::\\computer2\d$\path\installer.msi"

If it's not a problem with access control, then consider a similar problem I faced when copying files over servers with this error:

Cannot find path '\\computer1\d$\path' because it does not exist.

It works after adding Microsoft.PowerShell.Core\FileSystem:: in front of file name:

copy-item "Microsoft.PowerShell.Core\FileSystem::\\computer1\d$\path\installer.msi" "Microsoft.PowerShell.Core\FileSystem::\\computer2\d$\path\installer.msi"
梦里兽 2024-12-06 13:45:23

编辑:

我能够重现这个问题,这可能是双跳问题。我按照此处的说明解决了它:

http:// blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx

(或马特给出的链接)


确保computer2 和其他计算机能够看到该共享。如果其他计算机一开始就无法看到共享,则 Powershell 将无法执行任何操作。

对于简单的检查,请执行以下操作:

Invoke-Command -computer computer2 -script {dir \\computer1\txtfiles}

Edit:

I was able to reproduce this and it can be the double-hop issue. I solved it as per the instructions here:

http://blogs.msdn.com/b/clustering/archive/2009/06/25/9803001.aspx

( or the link that Matt had given)


Make sure computer2 and other computers are able to see that share. If the other machines are not able to see the share in the first place, Powershell cannot do anything.

For a simple check do:

Invoke-Command -computer computer2 -script {dir \\computer1\txtfiles}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文