通过调用命令调用时,使用Get-childitem的Cant Access unc路径

问题描述 投票:1回答:1

假设我在"\\somepath\somefolder"这样的域中具有路径。该文件夹可从该域中的所有服务器访问。但是在维护过程中,我们遇到了问题,并检查了我在以下代码中使用的所有服务器是否仍可访问该路径] >

foreach($server in $servers){
invoke-command -computername $server -scriptblock{
get-childitem -path "\\somepath\somefolder" -erroraction continue
}
}

它抛出错误,不知道为什么...

找不到路径'\\ somepath \ somefolder',因为它不存在。+ CategoryInfo:ObjectNotFound:\\ somepath \ somefolder:String)[Get-ChildItem],ItemNotFoundException+ FullyQualifiedErrorId:PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand+ PSComputerName:服务器名

如果我在每台服务器上都执行以下操作,则通常可以访问该路径

get-childitem -path "\\somepath\somefolder"

请注意所有服务器都在同一个域中并且是受信任的。

get-childitem -path "FileSystem::\\somepath\somefolder"

让我在这样的域中有路径“ \\ somepath \ somefolder”。可以从该域中的所有服务器访问此文件夹。但是在维护过程中,我们遇到问题并检查路径是否仍然...

powershell get-childitem
1个回答
0
投票

这是一个双跳问题。使用PowerShell远程连接到远程计算机并尝试向该计算机外部的资源发出命令后,您可能会收到此消息。 CredSSP可以解决此问题,但它的安全性较低。您可以将凭据用于远程会话,并将其重新用于以后的连接。代码:

foreach($server in $servers){
Invoke-Command -ComputerName $server -ScriptBlock { Register-PSSessionConfiguration -Name TheSession -RunAsCredential 'credential' -Force }
invoke-command -computername $server -scriptblock{
get-childitem -path "\\somepath\somefolder" -erroraction continue
} -ConfigurationName TheSession
}
© www.soinside.com 2019 - 2024. All rights reserved.